0

For my Asp.Net MVC signup project, I'm trying to add Captcha for human validation.

Here I have downloaded the NuGet package called CaptchaMVC5.

In the view In the manual, it asked to add it as,

@using CaptchaMvc.HtmlHelpers;

<div class="form-custom form-label form-icon mb-3" id="captchaText">
   @Html.Captcha(5)
   <p class="text-danger"> @ViewBag.ErrorMessage</p>
</div>

So I created a ajax call to check the captcha is valid or invalid

$.ajax({
  type: "POST",
  url: '/Account/CaptchaCheck',
  data: {},
  success: function (data) {
    if (data.Success == true) {
      
    } else {

      toastr.error(data.errorMsg);

    }

  },
  error: function () {

    alert("Pleas try again");

  }
})

This is the Controller code I wrote

public JsonResult CaptchaCheck() {
  if (!this.IsCaptchaValid("")) {
    return Json(new {
      Success = true,
        errorMsg = "Captcha Is Invalid"

    }, JsonRequestBehavior.AllowGet);
  } else {
    return Json(new {
      Success = false,

    }, JsonRequestBehavior.AllowGet);
  }
}

I want to know is there any way of sending the captcha from the ajax call to the controller and check the captcha is valid or invalid.

Dev Beginner
  • 589
  • 1
  • 11

0 Answers0