Question

I am working on an ASP.NET MVC based CMS that presents a rather extreme case. The system must allow the user to add custom content types based on different fields, and for every field, one can add options and validations. The thing is that everything is stored in a complex DB and extracted at runtime using LINQ.

I am pretty fresh with ASP>NET MVC so the following dilemma came to mind How should I make the content creation view so that form helpers are not predefined int he view code but are loaded based on the type of the field ? Do I have to create a factory class that checks the value of the type property of the field, and then returns a helper based on that or there's a better way to do it. This one seems pretty rigid to me , because anytime I make a change in the Fieldtypes table, I will have to make sure to create a check for that new type too.

public class CType {
  string Name; //e.g Post Article etc
  List<ContentData> data ;
...
}

public class ContentData {
  string Data; // Basically this is the data stored for each field
  FieldInstance fieldInstance; 
...
}

public class FieldInstance {
  string Title; // e.g Title Body etc.

  FieldType Type ; // e.g textbox textarea image checkbox etc
...
}

public class FieldType {
  string Type; // e.g textbox textarea image checkbox etc
...
}
Was it helpful?

Solution 2

I did not know about the concept of templated helpers. This is what happens when you're new to something. Pretty much, this is what fixed my problem

http://msdn.microsoft.com/en-us/library/ee308450%28VS.100,printer%29.aspx

OTHER TIPS

I see an HTML Helper in your future. The HTML Helper can work through your Model at runtime and output the appropriate HTML for the View. If you go that route, I suggest you get to know the StringBuilder and TagBuilder classes. They'll simplify things and help make your HTML Helper much more readable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top