Controller public ActionResult BookCourse(string Id) { services(); var item = _courseDetailsService.GetAll(); ViewBag.Code = Id.ToString(); ViewBag.Course = item; TempData["code"] = Id; ViewBag.title = "Booking Course"; ViewBag.Flag = false; return View(); } [HttpPost] [RecaptchaControlMvc.CaptchaValidator] public ActionResult BookCourse(CourseBooking book, bool captchaValid, string captchaErrorMessage) { try { services(); string code = TempData["code"].ToString(); bool valid = true; if (!captchaValid) { ViewBag.ErrorMessage = "Invalid Entry *"; ModelState.AddModelError("Captcha", "Please Enter verification text correctly"); valid = false; } if (book.FirstName == null || book.FirstName == "") { ModelState.AddModelError("FirstName", "Enter First Name"); valid = false; } if (book.LastName == null || book.LastName == "") { ModelState.AddModelError("LastName", "Enter Last Name"); valid = false; } if (book.EmailAddress == null || book.EmailAddress == "") { ModelState.AddModelError("EmailAddress", "Enter Email Address"); valid = false; } else { string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; Regex re = new Regex(emailRegex); if (!re.IsMatch(book.EmailAddress)) { ModelState.AddModelError("Email", "Email Address is not valid"); valid = false; } } if (!valid) { ViewBag.Flag = true; return BookCourse(code); } book.DateBooked = DateTime.Now; _courseBookingService.Add(book); SendNotificationMail(book); } catch(Exception ex) { _log.Log(ex); } return RedirectToAction("Thanks"); } View(Book Course) @if ((bool)ViewBag.Flag) { <div id="note"> <div class="notification_error"> @Html.ValidationSummary(false) </div> </div><!-- End notification --> }
ViewBag
ViewBag.Flag
if
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)