-1

I want to display two different error message. First give for required and second for Int64 value. Here is my code.

    [Display(Name = "Employee")]
    [Required]
    public Int64 EmployeeId { get; set; }
Ian Nelson
  • 57,123
  • 20
  • 76
  • 103
  • 2
    What does 'second for int64 value' mean? – tymtam Jun 21 '13 at 08:45
  • 'second for int64 value' mean : by default if i give string value in text box. That case it give error message 'The field must be a number'. But i want to display other message. – Karan Kumar Jun 21 '13 at 08:51
  • Possible duplicate [How to change the default “The field must be a number”](http://stackoverflow.com/questions/11831721/how-to-change-the-default-the-field-must-be-a-number) – Zabavsky Jun 21 '13 at 08:54

2 Answers2

1

You can use the RangeAttribute.

[Required(ErrorMessage = "Msg1")]
[Range(10, 1000, 
    ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public object Weight;
tymtam
  • 31,798
  • 8
  • 86
  • 126
0

You can use data annotation extentions here: http://dataannotationsextensions.org/

Then add the two annotations as follows:

[Required(ErrorMessage = "Employee Id is required")]
[DataAnnotationsExtensions.Integer(ErrorMessage = "Please enter a valid number.")]
public Int64 EmployeeId { get; set; }
MiiisterJim
  • 419
  • 1
  • 4
  • 16