ASP.NET Data Annotations: How to share with a JSON client? ASP.NET Data Annotations: How to share with a JSON client? json json

ASP.NET Data Annotations: How to share with a JSON client?


See this blog post.

Essentially you call an MVC Html Helper method <% Html.EnableClientValidation();%> that outputs some JSON onto the page. Then there is a translation method in the MicrosoftMvcJQueryValidation.js that feeds jquery validate with the data annotations for each field.


Update for comments

If you are rendering the HTMLFormElements without using mvc controls it will be much more difficult. You will probably need to look at the ViewData.ModelMetadata to access the data annotations. Possibly need to use a custom MetaDataProvider I would consider going to MVC3 RC so I could use th unobtrusive validation (data attribute)

Here are some links: