How to determine there is no error in Model State?

When server side model validation fails, errors are included in the ModelState. Hence, by using ModelState.IsValid property you can verify model state. It returns true if there is no error in ModelState else returns false.

[HttpPost]
		public ActionResult DoSomething(UserViewModel model)
		{
			if (ModelState.IsValid)
			{
				//TODO:
			} return View();
		}
Tagged , . Bookmark the permalink.

Leave a Reply