Please help me to understand why captcha does not work correctly. Captcha is displayed during registration, if not entered or entered correctly, registration does not pass. However, error messages or the successful entry of values ​​does not display! Namely, there should be messages: TempData["Message"] = "Message: captcha is valid." and TempData["ErrorMessage"] = "Error: captcha is not valid." . I'm sure that I made some kind of painfully stupid mistake, but I can't find it !!

How to implement:

Installed using Nu GET CaptchaMVC .

Controller:

 //... public class AccountController : Controller { // POST: /Account/Register [HttpPost] public ActionResult Register(RegisterModel model, string empty ) { if (this.IsCaptchaValid("Captcha is not valid")) { TempData["Message"] = "Message: captcha is valid."; } if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, "question", "answer", true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { MigrateShoppingCart(model.UserName); FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } TempData["ErrorMessage"] = "Error: captcha is not valid."; } // If we got this far, something failed, redisplay form return View(model); } 

Model:

 public class RegisterModel { [Required] [Display(Name = "User name")] public string UserName { get; set; } [Required] [DataType(DataType.EmailAddress)] [Display(Name = "Email address")] public string Email { get; set; } [Required] [StringLength(100,ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirm password")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; } [Required] [DataType(DataType.PhoneNumber)] public string Phone { get; set; } } 

View:

  @model MvcCosmeticsStore.Models.RegisterModel @using CaptchaMvc.HtmlHelpers @{ ViewBag.Title = "Register"; } <h2> Create a New Account</h2> <p> Use the form below to create a new account. </p> <p> Passwords are required to be a minimum of @Membership.MinRequiredPasswordLength characters in length. </p> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (Html.BeginForm()) { @Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.") <div> <fieldset> <legend>Account Information</legend> <div class="editor-label"> @Html.LabelFor(m => m.UserName) </div> <div class="editor-field"> @Html.TextBoxFor(m => m.UserName) @Html.ValidationMessageFor(m => m.UserName) </div> <div class="editor-label"> @Html.LabelFor(m => m.Email) </div> <div class="editor-field"> @Html.TextBoxFor(m => m.Email) @Html.ValidationMessageFor(m => m.Email) </div> <div class="editor-label"> @Html.LabelFor(m => m.Password) </div> <div class="editor-field"> @Html.PasswordFor(m => m.Password) @Html.ValidationMessageFor(m => m.Password) </div> <div class="editor-label"> @Html.LabelFor(m => m.ConfirmPassword) </div> <div class="editor-field"> @Html.PasswordFor(m => m.ConfirmPassword) @Html.ValidationMessageFor(m => m.ConfirmPassword) </div> <div class="editor-label"> @Html.LabelFor(m => m.Phone) </div> <div class="editor-field"> @Html.TextBoxFor(m => m.Phone) @Html.ValidationMessageFor(m => m.Phone) </div> <div class="editor-field"> @Html.Captcha("Update", "Enter security code:", 5, "Required field", true) </div> <p> <input type="submit" value="Register" /> </p> </fieldset> </div> } 

    0