I want to add the ability to build a form in my app. The user adds input fields to the form in the UI of my app, and for each form element she can specify data-type.
I use ASP.NET MVC 3, and want to use as much as I can of the validation mechanism supported by the frameworks. For my own forms in the app, I decorate each ViewModel with dataannotations to and use client validation.
Is there any way I can add those annota开发者_高级运维tions to a dynamic ViewModel?
It's fine to use e.g. @Html.TextBox("name")
, but how do I mimic the data annotations, so that jQuery Validate and the unobtrusive plugin picks them up correctly?
Have you tried adding the data-dash-attributes like this? (Hint: Use an underscore instead of the dash, it will be translated to a dash in the according attribute)
@HtmlTextBox("name", new { data_... = "some value", data_... = "some value" })
精彩评论