views:

294

answers:

2

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
...
}
+1  A: 

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.

DM
the thing seems very complicated to me right now. Imagine that I have a "picture" field in the content type, which means that when I am adding content, it has to provide a form with a browse button, and when I am viewing this same piece of content, it must display the picture itself, without explicitly saying anything in the views.
Can you edit your question real quick and show me an example of the object you would pass the view to display your content. If I see that I can show you a quick code example.
DM
i've put here a very simplistic version of what my code is about. Assume that I'm passing the view with a bunch of ContentData vars, and based on the FieldInstance type, and the type of the view (Create, Edit, Index ...) the appropriate helper is chosen. In the above example, the Create view will display a form with a browse button, and the index view will display an image based on the address contained in the Data field. Hope, you can get it.
A: 

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