Monday, June 9, 2014

ModelState.AddModelError to add a simple validation

Use ModelState.AddModelError to add a simple validation and make the ModelState.isValid with errors.



   // Validation logic
   if (MyData.Email.Trim().Length == 0){
        ModelState.AddModelError("Email", "Invalid Email");
   
        return View(MyData);
   }


No comments:

Post a Comment