This project is read-only.

MVC captcha

MVC captcha and MVC invisible captcha.
Ajax captcha validation. Easy and simple to use.




Download and add model (CaptchaModel.cs), controller(CaptchaController.cs) and partial(_Captcha.cshtml,_InvisibleCaptcha.cshtml) view to your project.

Inside form add partial views.

@using (Html.BeginForm()) {

    <div class="editor-label">
        @Html.LabelFor(model => model.Text)
    <div class="editor-field">
        @Html.EditorFor(model => model.Text)
        @Html.ValidationMessageFor(model => model.Text)

    @Html.Partial("_Captcha", new Uco.Models.Captcha())
    @Html.Partial("_InvisibleCaptcha", new Uco.Models.InvisibleCaptcha())

        <input type="submit" value="Send" />

In controller check captcha:


public ActionResult Index(string CaptchaValue, string InvisibleCaptchaValue)
	bool cv = CaptchaController.IsValidCaptchaValue(CaptchaValue.ToUpper());
	bool icv = InvisibleCaptchaValue == "";

	if (!cv || !icv)
		ModelState.AddModelError(string.Empty, "Captcha error.");
		return View();

	if (ModelState.IsValid)
		// do work

		return View();
	else return View();

Last edited Mar 23, 2012 at 8:24 AM by andreydruz, version 15