IValidatableObject in MVC3 - client side validation

眉间皱痕 提交于 2019-11-27 07:58:17
Paul Hiles

As I did not get a (valid) answer here, I asked a couple of people from Microsoft and they confirmed that it was not currently possible.

Brad Wilson:

At this time, only property level validators can emit client-side validation (as that lines up much better with the idea of input validation in the form of the browser... there is no "model" to speak of, from the browser's point of view).

Stuart Leeks:

I don't believe you can hook up client validation with IValidatableObject

http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx http://blogs.msdn.com/b/stuartleeks/archive/2010/07/28/asp-net-mvc-adding-client-side-validation-to-validatepasswordlengthattribute-in-asp-net-mvc-3-preview-1.aspx

ASP.NET MVC 3 now honors the IValidateObject interface when model binding (in addition to all of the other validation approaches it already supported with MVC 2), and will retrieve validation errors from it and automatically flag/highlight impacted fields within a view using the built-in HTML form helpers.

ASP.NET MVC 3 also introduces a new IClientValidatable interface that allows ASP.NET MVC to discover at runtime whether a validator has support for client validation. This interface has been designed so that it can be integrated with a variety of validation frameworks. MVC 3 also introduces a new IMetadataAware interface that simplifies how you can contribute to the ModelMetadata creation process.

This article describes a way to access the container object in client side validation in ASP.NET MVC. You can probaly use this to get started on using your own client side validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!