Dynamic (Runtime Generated) Forms in ASP.NET MVC

Robert Claypool picture Robert Claypool · May 29, 2009 · Viewed 29.4k times · Source

This is a general design question: How would you implement a dynamic (runtime generated) form in ASP.NET MVC?

Here's the situation:

  1. A site admin can define form parameters (fields, type of fields, validation) with a GUI (MVC view).
  2. As needed, the runtime generates the form for the end user based on the admin configuration. I'm assuming that all of this logic would reside in the controller - or perhaps extension methods, action filters or something like that.
  3. End user fills out the form, hits submit, information is captured in database.

The customization does not need to support nested controls, 3rd party controls and so forth, but I suspect a very elegant design would allow for that. Mostly, I just need the admin to be able to specify additional fields as textboxes, checkboxes, radio buttons and comboboxes. I will also need the application to allocate a space for this data to be saved in the db, but I believe I have that part figured out.

Thanks for the help.

Answer

Ronnie Overby picture Ronnie Overby · Feb 1, 2010

I had the same need in a recent project. I created a class library for this. I just released a new version of the library.

Maybe it can help you: ASP.NET MVC Dynamic Forms