开发者

MVC 3 client-side validation without annotation?

Is there a way to have the same kind of client-side validation in MVC 3 without being able to set the validation at the viewmodel level? I have two requirements that are preventing me from adding my validation at the viewmodel level. I'd like to be able to have the same kind of "built-in" validation but without changing the viewmodel or controller code. I'd like to be able to change, turn on/off, validation at the view level post-deployment. Ideally I'd like to be able to edit the view mark-up without writing and maintaini开发者_如何转开发ng mountains of my own JavaScript.


http://bassistance.de/jquery-plugins/jquery-plugin-validation/

This may help ya, only validation on the client though so not really ideal.


You could create your own TypeDescriptionProvider which will allow to augment your viewmodel at runtime.

Based on this code sample (XmlMetadataTypeDescriptor, XmlMetadataTypeDescriptionProvider) you should be able to:

  1. Augment viewmodel using external xml which contains validation attributes.
  2. Turn on validation with

    TypeDescriptor.AddProvider

  3. and turn it off with:

    TypeDescriptor.RemoveProvider

Update

For more information you can read great article: "Understanding the TypeDescriptor: A Metadata Engine for Designtime Code".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜