开发者

How to include unobtrusive javascript validation in your HtmlHelpers?

开发者 https://www.devze.com 2023-03-22 14:30 出处:网络
I have written my own HtmlHelper and now want to integrate Unobtrusive Validation (e.g. http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html)

I have written my own HtmlHelper and now want to integrate Unobtrusive Validation (e.g. http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html)

Is there a quick way to do this, to save interrogating开发者_StackOverflow the Model's Property's attributes and adding the data-val-etc HTML attributes to the HTML string that is built?


The GetUnobtrusiveValidationAttributes() method is used in the MVC3 source:

See:

  • http://msdn.microsoft.com/en-us/library/gg416607(v=vs.98).aspx
  • System.Web.Mvc.Html.InputExtensions.cs:371


Appending the output of Html.ValidateFor() for the specific field should take care of it. Generally the ValidateFor() just outputs the validation logic and messages for a specific field. I may be missing something based on how I interpreted your question, but if I understand correctly that should solve it.

0

精彩评论

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