开发者

ASP.NET MVC Validate dynamic form elements

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" })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜