Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

asp.net mvc 3 - IValidatableObject in MVC3 - client side validation

With MVC3 you have two new mechanisms for adding custom validation. These are (1) subclass ValidationAttribute or (2) implement IValidatableObject.

The ValidationAttribute allows you to add client side validation relatively simply by implementing IClientValidatable (and registering a new adapter and method via jQuery).

IValidatableObject is more suited to one-off validation requirements where reuse is not an option. It also results in slighlty simpler code. It would therefore be my choice for a number of scenarios. Unfortunately, I do not see an easy way of implementing client side validation using this method.

So the question is what am I missing and how DO you get JS validation when using IValidatableObject?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...