Tutorial by Examples

[HttpPost] public ActionResult ContactUs(ContactUsModel contactObject) { // This line checks to see if the Model is Valid by verifying each Property in the Model meets the data validation rules if(ModelState.IsValid) { } return View(contactObject); } The model class p...
Say you have the following model: public class foo { [Required] public string Email { get; set; } [Required] public string Password { get; set; } [Required] public string FullName { get; set; } } But you want to exclude FullName from the modelvalidation becaus...
If you want to provide Custom Error Messages you would do it like this: public class LoginViewModel { [Required(ErrorMessage = "Please specify an Email Address")] [EmailAddress(ErrorMessage = "Please specify a valid Email Address")] public string Email { get; set...
Let's say that you have the following class: public class PersonInfo { public int ID { get; set; } [Display(Name = "First Name")] [Required(ErrorMessage = "Please enter your first name!")] public string FirstName{ get; set; } [Display(Name = "L...
In cases where you need to ensure model validation using Jquery, .valid() function can be used. The model class fields [Required] [Display(Name = "Number of Hospitals")] public int Hospitals{ get; set; } [Required] [Display(Name = "Number of Beds")] public int Beds { get; ...

Page 1 of 1