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.
Wednesday, June 26, 2013
Validating Number/Decimal in ASP.NET MVC
Subscribe to:
Post Comments (Atom)
No comments:
Write comments