How many times have you seen or written code like this ♻️ :
[HttpPost]
public ActionResult Index(SomeModel model)
{
if (ModelState.IsValid)
{
return View();
}
// do something
return RedirectToAction("index");
}
Stop repeating ModelState checks in your ASP.NET MVC controller actions. ❌
Wouldn’t it be nice if all we had to do was like this ? ⚡️
[HttpPost]
[ValidateModelState]
public ActionResult Index(SomeModel model)
{
// if we get here, ModelState is valid
// save to db etc.
return RedirectToAction("index");
}
https://t.me/pgimg/89
[ Article ] : http://bit.do/msta
〰〰〰〰〰〰
#AspMvc #CleanCode
@ProgrammingTip