1

I've just been reading the article on MSDN about remote validation. This is great, but it only shows validating a specific property value.

Is there a way I can pass other values from my model into the validation for a particular property? For example, let's say that a user wants to cancel a number of items off an order - they should be prevented from entering a figure greater than the original order amount.

Thanks

2 Answers 2

2

No, you can't.

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

Sign up to request clarification or add additional context in comments.

3 Comments

Perhaps I'm approaching this problem from the wrong angle. Is there a better way?
I imagine that you have a TextBox where user should type in a number. If you are using a 'numeric' control than check if it supports MaxValue. If this is a plain input than render a validation javascript yourself then you render the page and know current number of items.
Thanks for your input Jakub. This will be a textbox as the value will vary greatly (from 1 to 10,000). I was hoping to avoid a solution that involved client-side validation and was trying to keep all this logic on the server - that was the original intension of looking at the Remote attribute, but I now understand that this isn't possible the way I thought.
1

Well, i am nit sure if you mean this, but you can use AdditionalFields with your RemoteValidation attribute.

Remote Validation in ASP.Net MVC 3: How to use AdditionalFields in Action Method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.