From 044c51ef8beb51e18b697335c0e3ff4d0f90243b Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 14 Jul 2021 21:33:55 +1000 Subject: [PATCH] e.g. 3.14 Checking for Form Validation Errors --- .../PartyInvites/Controllers/HomeController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs b/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs index 9020d90..a536625 100644 --- a/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs +++ b/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs @@ -37,8 +37,16 @@ namespace PartyInvites.Controllers [HttpPost] public ActionResult RsvpForm(GuestResponse guestResponse) { - // TODO: Email guestResponse to the part organizer - return View("Thanks" ,guestResponse); + if (ModelState.IsValid) + { + // TODO: Email guestResponse to the part organizer + return View("Thanks", guestResponse); + } + else + { + // there is a validation error - redisplay the for + return View(); + } } } } \ No newline at end of file