Hi to All...
I am new to the MVC anybody give detailed notes about Data Annotations MVC 4
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
NitinPosted Mar 31, 2015, 2:39 AM
In your models folder in MVC you create models. Now if you need to place validations on it you need to import the "using System.ComponentModel.DataAnnotations;" namespace.
Further for your properties you can use it like:
[Required(ErrorMessage="Please Enter ID")]
public int Id { get; set; }
[StringLength(15,MinimumLength=4)]
[Required(ErrorMessage = "Please Enter Name")]
public string Name { get; set; }
[Required(ErrorMessage = "Please Enter Price")]
public double Price { get; set; }
Follow the below links for detailed analysis:
MVC 4 Validation 1
MVC 4 Validation 2