You can build the library from the sources or install using NuGet package manager. Run the following command in the Package Manager Console:
PM> Install-Package MvcCaptchaLib

Generating captcha image

Write the following code to the controller's action method:
 public ActionResult GetCaptcha()
        return this.Captcha();

Validating captcha code

Write the following code to the model you use:
    public string Captcha {get;set;}

The validation then runs as usual and you can check is the model valid by accessing ModelState.IsValid property in your action method.

Rendering to the HTML

Write the following code to the view:
 @Html.CaptchaFor(m => m.Captcha, "GetCaptcha", "Is captcha unintelligible? Reload new one.")
@Html.ValidationMessageFor(m => m.Captcha)

Copy captcha.js file to your web application project. (This script uses Jquery 1.3+, make sure you also reference this as well.)

Add reference to the javascript like this:
<script type="text/javascript" src="@Url.Content("~/Scripts/captcha.js")"></script>


You can customize rendering by setting a number of properies of CaptchaImage instance. Also you can place a number of captches onto the single page by providing unique captcha identifiers to Captcha method and ValidateCaptcha attribute.

Last edited May 5, 2012 at 9:10 AM by leon_mz, version 2


jaybald Jan 4, 2013 at 7:05 PM 
Good work, but I cannot use it as the HTML does not render the way I need it. Suggestion would be to separate the image, from the refresh label (which should also be able to be an image) and the textbox. Make sure you can add styles to the textbox as well. Good luck!