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

dubs
  • 6,511
  • 4
  • 19
  • 35

2 Answers2

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

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
  • Perhaps I'm approaching this problem from the wrong angle. Is there a better way? – dubs Feb 15 '11 at 05:57
  • 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. – Jakub Konecki Feb 15 '11 at 06:01
  • 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. – dubs Feb 15 '11 at 06:15
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

Community
  • 1
  • 1
Bcelik
  • 1,216
  • 10
  • 10