Wednesday, June 26, 2013

Validating Number/Decimal in ASP.NET MVC


  public class Item
    {
        [Required]
        [Range(typeof(Decimal), "1", "9999", ErrorMessage = "{0} must be a decimal/number between {1} and {2}.")]
        public double ItemPrice { get; set; }
       
    }

Above shown data annotation will make sure that the ItemPrice property is only allowed to assign numbers between 1 and 9999.

Required Data annotation will make sure the value is not empty.

No comments:
Write comments
Recommended Posts × +