MVC captcha

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

EXAMPLE:

 

HOW 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()) {
    @Html.ValidationSummary(true)

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

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

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

In controller check captcha:

 

[HttpPost]
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 7:24 AM by andreydruz, version 15