Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Last active October 25, 2017 14:03
Show Gist options
  • Save dontpaniclabsgists/3c8868b30567553ae529842318bced4e to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/3c8868b30567553ae529842318bced4e to your computer and use it in GitHub Desktop.
validating_fields_mvc_3
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(MyModel myModel)
{
// IsValid will be false due to Validate
if (ModelState.IsValid)
{
db.MyModels.Add(myModel);
db.SaveChanges();
return RedirectToAction(nameof(Index));
}
return View(myModel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment