ASP.NET MVC3 Model Validation DataAnnotations to do less than or equal to another property with client side validation -


I have a simple form that is using ASP.Net MVC3 humorous client-side validation.

The model looks a bit like this (the name has been changed for privacy):

  public class MyInputModel {public MyInputModel () {} Public MyInputModel (MyViewData viewData) {ViewData = viewData; MaxValueForSize = ViewData Max size; } Public Inc. MaxValueForSize {get; Set; } [Regular expression ("[1-9] [0-9] *", error message = "value should be a whole number.")] Public full size {get; Set; } [String lang (255)] [required] public string description {get; Set; }}   

In my opinion, I put a hidden field for MaxValueForSize and I entered the value for the size I want to reduce the amount of MaxValueForSize is equal to or equal to the property.

I know that I can do this server with the override verification attribute:

  Internal class SizeValidAttribute: verification entry {protected override validation result IsValid (object value, Validation validation validation verification) {if (value! = Null) {var Model = (MyInputModel) validationContext.ObjectInstance; If ((int value) gt; model.MaxValueForSize returns a new verification return (error message); } The basis of return ISIAGID (Value, Verification Consolve); }}   

However I would like client-side valuation (required) on this property. Comparison Similar to how annotations work.

Do anyone know how to do this?

P> Take a look at this article It explains that ASP.NET MVC How to validate cross-field validation to expand model recognition:

Extension of ASP.NET MVC certification


Comments