I want to use DataAnnotations in mvc4 for valid value only for numeric but greater than 0, Please help.
Thanks.
There are two types of validations: Server side Validations. Client Side Validations.
In ASP.NET MVC, Data Annotation is used for data validation for developing web-based applications. We can quickly apply validation with the help of data annotation attribute classes over model classes.
Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.
You could use the [Range]
attribute:
[Range(1, int.MaxValue, ErrorMessage = "The value must be greater than 0")]
public int Value { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With