0

I am new to MVC4. I have a MyModel class with "public string myValue" member. I need to validate it's value, on the Client Side (after user enters it in View) against maximum value (maxVal) that is retrieved from database and belongs to the different model (DiffModel). I have tried [Range(..] validation attribute, but it requires const parameters. I am looking now into creating custom validation attribute (cva), but it looks like cva will run on Server side, and Not on client side. Please suggest how to resolve with this situation if it's possible at all. Thank you

tereško
  • 58,060
  • 25
  • 98
  • 150
Karen Slon
  • 233
  • 1
  • 4
  • 16

1 Answers1

0

Example of how you do it:

public class ViewModel
{
    public DateTime MinDate {get; set;}
    public DateTime MaxDate {get; set;}

    [DynamicRange("MinDate", "MaxDate", ErrorMessage = "Value must be between {0} and {1}")]
    public DateTime Date{ get; set; }
}

Changing validation range programmatically (MVC3 ASP.NET)

Community
  • 1
  • 1
JC Lizard
  • 1,050
  • 6
  • 17