Link to home
Start Free TrialLog in
Avatar of ksd123
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?

        [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; }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ksd123
ksd123

ASKER

Thank you so much.