Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way to do this is to create your own <code>ModelBinder</code> which would be at the heart of your generated forms. A modelbinder is responsible for validating the <code>ModelState</code> and rebuilding the typed <code>ViewDataModel</code> (assuming your views are typed). </p> <p>The <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471" rel="nofollow noreferrer">DataAnnotations</a> model binder could be a good reference for this what this custom modelbinder allows you to do is via <code>Attributes</code> on your <code>ViewDataModel</code> describe the attribute's validation (and hint at UI rendering). However this is all defined compile time but would be a great reference to start off writing a custom modelbinder.</p> <p>In your case your model binder should get the validation for a field at runtime from an xml file/string. </p> <p>If you have a route like:</p> <pre><code>routes.MapRoute(null, "Forms/{formName}/", new { action = "Index", controller = "Forms", formName = ""}), </code></pre> <p>Then you could locate the correct form xml in <code>FormsController.Index(string formName)</code> and pass it to the view.</p> <p>The <code>FormsModel</code> should hold all the possible methods to get data I dont see any other way around this. The Xml could map to a function name (possibly even arguments) that you can invoke using reflection on the <code>FormsModel</code> to fill the <code>ViewData</code> or typed <code>ViewDataModel</code> with data.</p> <p>The view for Form Index could generate a form from that xml through an <code>HtmlHelper</code> Extension that takes an <code>XmlDocument</code>.</p> <p>Then when you (or asp.net mvc) binds your form to your <code>ViewData</code> your custom model binder is invoked it can inspect the current controller values to look for the formName and look up the corresponding xml that holds all the validation rules. The <code>ModelBinder</code> is then responsible for filling up <code>ModelState</code> with any runtime defined errors.</p> <p>It's a hard task but when pulled off succesfully well worth it in my view :)</p> <p><strong>Update</strong> a better alternative to model data would be a very loose database schema as David Liddle suggests. I'd still go through the trouble of saving it as xml (or someother serialized format) and using that for generating the view and to hold validation rules for a custom <code>ModelBinder</code> so that you have more control on layout and validation of each field.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload