ksd123
asked on
Decimal validation using data annotations using c#
Hi Experts,
I am using data annotations to validate Model properties using MVC5 and need to validate decimal property which is both Required and Range which must be between 2 and 100.
If I don't enter any data for Price field ie. 0 (since it is decimal) the Required validation message should show.But in both the cases(Required and Range) Range validation message is showing.Can anyone guide me what went wrong in the below code snippet?
I am using data annotations to validate Model properties using MVC5 and need to validate decimal property which is both Required and Range which must be between 2 and 100.
If I don't enter any data for Price field ie. 0 (since it is decimal) the Required validation message should show.But in both the cases(Required and Range) Range validation message is showing.Can anyone guide me what went wrong in the below code snippet?
[Required(ErrorMessage = "The Price is required")]
[Range(2.00, 100.00, ErrorMessage = "The Price must be between 2 and 100")]
public decimal Price { get; set; }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER