Last active
October 25, 2017 14:03
-
-
Save dontpaniclabsgists/3c8868b30567553ae529842318bced4e to your computer and use it in GitHub Desktop.
validating_fields_mvc_3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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