Reputation: 3066
I'm new to MVC and ADO.net Entity Framework. Instead of having to create an edit/display for each entity, I'd like to have the controller base class generate the view and validation code based off metadata stored in a table - something along those lines.
I would imagine something like this has already been done, or there are good reasons for not doing it. Any insight or suggestions are appreciated.
Upvotes: 1
Views: 263
Reputation: 3066
I don't like to answer my own question, but I found a library - [ASP.Net Dynamic Forms][1] - which was pretty much exactly what I needed.
It's pretty well written, isn't too complicated and easily extensible. The source author leaves the implementation very open ended, so far, I've been able to easily create a sql layer where the form settings reside, code looks something like this -
` string controllerName = controllerType.ToString();
Form form = new Form();
List<FormSetting> settings = new DataEntities().FormSettings.Where((c => c.ControllerName == controllerName)).ToList();
foreach (FormSetting setting in settings)
{
Field fieldToAdd = CreateField(setting);
form.Fields.Add(fieldToAdd);
}`
[1]: http://mvcdynamicforms.codeplex.com/ .
Upvotes: 0
Reputation: 50728
The display can be done using Html.DisplayForModel() or Html.EditorForModel(). This generates a view for the entity to render, but it probably won't look the way you like. I think it might inject validators, but that is based of data annotations, not the LINQ to Entity DB metadata.
As far as I know, I don't know of anything that automatically sucks in L2E model metadata... I was thinking of writing something myself too, as it would be very convenient to have.
HTH.
Upvotes: 1