About .NET, ASP.NET, MVC, C#, WPF, WCF and everything related to .NET and more.

Captcha Mvc [Demo (Plain captcha)]

The captcha render with Html.Captcha("Try another", "Enter the text you see above:", 5, "Is required field", true)

Enter the text you see above:


I really liked this post and I implemented the solution for our site. I've a query relating to showing client side validation. Is there a way i can pass my model property which contains required attribute and attribute to check if captcha is valid or not.

Currently I check if captcha is valid as per your sample code in controller as following. I would like to show error message below the auto generated input field. With below code the textbox background color is changed to red but the message is not show.

'sample code
If Not Me.IsCaptchaValid("Captcha is not valid") Then
ModelState.AddModelError("CaptchaInputText", "Captcha is not valid")
Return View()
End If

Hi Vaibhav,
Try to create a captcha using the code:

var captcha = Html.Captcha("Refresh", "Input", 5, "Is required field.", false);
or for the math captcha:
var mathCaptcha = Html.MathCaptcha("Refresh", "Input", "Is required field.", false);
then in controller you can write this code:
this.IsCaptchaValid("Captcha is not valid")
and Captcha is not valid message will be automatically showed in the auto generated input field.

hi frnd
plz send complete code :rairahul9934@gmail.com this mail id

Hi Vyacheslav,

Thanks a lot for your solution. It worked like a charm..!! :)

Hi Vyacheslav,

While testing the captcha I found out that the captcha checks the text case insensitive. Is there any attibute that i can set to check the captcha should be checked for case.

As per my understanding the CAPTCHA image is always generated in uppercase.?

Thanks for your help.

Hi Vaibhav,
As per my understanding the CAPTCHA image is always generated in uppercase.?
Yes, these "QWERTYUIPASDFGHJKLZCVBNM" symbols are used by default. You can change it using this code:

protected void Application_Start()
    var captchaManager = (DefaultCaptchaManager) CaptchaUtils.CaptchaManager;
    captchaManager.CharactersFactory = () => "my characters";
Is there any attibute that i can set to check the captcha should be checked for case.
Yes, you can change this behavior using this code:
captchaManager.PlainCaptchaPairFactory = length =>
string randomText = RandomText.Generate(captchaManager.CharactersFactory(), length);
bool ignoreCase = false;//This parameter is responsible for ignoring case.
return new KeyValuePair<string, ICaptchaValue>(Guid.NewGuid().ToString("N"),
    new StringCaptchaValue(randomText, randomText, ignoreCase));

Thanks it helped. Also noticed that after this change the captcha is generated in mixed mode i.e with letter and number and symbols also with upper and lower case mix.


Thanks ...Case sensitive issue is reolved

This seems like a good solution BUT would be nice if you actually had the complete code and how this fits within a form post (maybe with one other non-captcha input). I don't know if I am missing something or need to browse through the dll but some things aren't adding up. But I am sure once it becomes clear I will go AHA! For now I think the solution could use a little more clarity. ( ;

Is there a way to catch this on the client side before doing a post?

Hi, How can i check validation for Captcha in Javascript.

Is it possible to only show numbers in captcha?

I am wondering how can I set url link for Refresh picture redirection. Thanks.

Could it be that there is a bug with the .IsCaptchaValid() method? It always return false, whether I type the correct captcha or the incorrect captcha. That is really annoying!!!

Can you provide more information about the problem, or could you please give a demo project to demonstrate this issue?
When did it happened, during debugging or in production?
Which version of CaptachMvc are you using?
Which version of MVC are you using?
Did you have any exception when the captcha was created?

Hi, I hope you are well.

I started to use this library to replace google's reCaptcha code because of organizational requirements.
Great functionality and code. You did a nice work! congratulations.

I noticed as Superbyte that the method IsCaptchaValid() has a bug and indeed shows that the captcha is not valid when it is.

I'm using your MVC4 example project.
This happened in development machine during debugging.
I'm using the version and i have no exceptions when captcha was created.

The strange thing is that i integrated this captcha code to another project and in development during debugging the method IsCaptchaValid is not showing the bug...

Could you provide a solucion or a hint about what's happening?


I forgot to mention that in the second project I'm using MVC4, no exceptions or errors are showed during captcha creation and the library version is too. Thanks!


I found the fix to this behaviour.

Let's say that you have this controller method:

[HttpPost, CaptchaVerify("Captcha is not valid")]
public ActionResult PartialCaptchaView(string empty)
//...your code...
if (this.IsCaptchaValid("Captcha is not valid")){
//more code..
//more code...

to make method "IsCatpchaValid" work you just have to remove "CaptchaVerify" inside the brackets.
If you want to use "ModelState.IsValid" property leave "CaptchaVerify" inside the brackets.

I hope this helps and sorry for the previous reply.


I am getting the error below when I see my form page with Developer Tools (F12) in Chrome:

"Uncaught ReferenceError: $ is not defined"

In page source code:

$(function () {$('#1be752a6bbab42f687fda6c4f4f64dc7').show();}); <<--- ERROR IN THIS LINE !!!
function 53ccf101899b4ae6959118467563d157() { $('#1be752a6bbab42f687fda6c4f4f64dc7').hide(); $.post("/Maclau.Web/DefaultCaptcha/Refresh", { t: $('#CaptchaDeText').val() }, function(){$('#1be752a6bbab42f687fda6c4f4f64dc7').show();}); return false; }</script>

Do you know how to remove this error ?


Hi Marcelo,

Maybe you haven't added JQuery script, try to declare jQuery script in your layout page and put it in the head tag or try to split the captcha markup and script generation.

I would like to have image instead of refresh as text. How to do that?

Hi Joyce,

If you need a flexible set-up, I advise you to use the partial-view, with their help, you can fully control the markup for captcha.
Examples of forms:

Captcha image is not rendered. I am using CaptchaMvc.Mvc4

How I add class for this input


The captcha render with Html.Captcha("Try another", "Enter the text you see above:", 5, "Is required field", true)

The "Try another" option doesn't appear. How can i put it?


Is there any way to do the "Try another" in ajax mode ? In my MVC project, every time I click the link, the page is posted and it rolls the scrollbar. I´d like to change de code without rolling the page....

Another doubt is if I can use an image in this link.


Hello, how can i implement this captcha without page being re positioned on refresh?i.e every time i tried to refresh captcha the page gets pulled(scrolled) down..so how can i set this issue?and also how can i customize the refresh button look?please help..

hey,,i found the example http://captchamvc.codeplex.com/releases/view/114341 wich doesn' t pulls down the page on refresh captcha(uses ajax)....


Where is that example? I don't find The solution.

captcha showing as black in safari and iphone can you help me fix this

I have the same problem. captcha is a black image on safari and Iphone. thanks

I need to add audio to this captcha, can u guide me?

Can you please explain how to validate Captcha-MVC using ajax post method without using any form.

I implemented captcha in my contact form.

var captcha=Html.Captcha("Refresh", "Input", 5, "Is required field.", false);

Here,it shows error message as " captcha" does not exist in current context.
What I did wrong in this? please advise.


I'm validating captcha in JsonResult Action. But if i put wrong captcha and my JsonResult method returns false. But captcha is not reloading. I want to reload captcha for this.

Can I make the captcha check optional. For example it should not validate when user is logged in and authenticated? only show for users who are not authenticated

I Use Captcha Mvc. But it dot work correctly.
in page load in console show
GET http://localhost:12062/BotDetectCaptcha.ashx?get=layout-stylesheet error

and after first submit click the pictuer dont change and dont refresh manually
by this error
jquery-1.10.2.min.js:6 POST http://localhost:12062/DefaultCaptcha/Refresh 500 (Internal Server Error)
please help


Please tell me , can we use refresh icon instead of Try Again text?

Hello. Yes You Can.

Thank You. it is very good.


How can i check Client side validation for captchMvc.
present its working in serverside but i want to check in client side only.

Hi, is it possible to add audio (voice over) with this? Or perhaps get the captcha string in controller so that I can implement the audio function?

Refresh button not show in my website

string captchaenable = System.Configuration.ConfigurationManager.AppSettings["CaptchaEnabled"];

if (captchaenable == "True")
@Html.Captcha("Refresh", "<b>Captcha Code:</b>", 5, "Is required field", false)<p>@ViewBag.ErrMessage </p>

I am not able to validate the Captcha..every time it is returning false only..what can be the issue

I have the same issue I cannot validate the math captcha:

if (!this.IsCaptchaValid ("Validate your captcha"))
{ModelState.AddModelError("", "Invalid captcha!");} is always false.

I use this in my view: <div>@Html.MathCaptcha()</div>


type: "POST",
url: "/ProductCatalog/IspratiRequest/",
data: { ProductID: product, Name: name, Email: email ,Phone:phone, Message: message},
success: function (result) {



Please help

Did you find an answer to this ?

is this works like an alphanumeric captcha ?

Does it validate using jquery?

Hi Vyacheslav,

Can we achieve alphanumeric Captcha with it instead of only letters ??? can you pls suggest if we can do so ??


How can use captcha mvc by jqury without submit button and refreshing page?

I want use captcha mvc by jqury without submit button and refreshing page?
What is the solution for this purpose?

Hi Moosa,

@using (Ajax.BeginForm("GetExtensionDetails", "BuyTakafulInsurance", new AjaxOptions { HttpMethod = "POST", OnSuccess = "OnSuccessVisitVisa", OnFailure = "OnFailureVisitVisa", OnBegin = "OnBeginVisitVisa" }, new { id = "frm" }))
<button type="button" id="btnNext">

$("#btnNext").click(function () {



CaptchaMVC loads with big black box with red cross line
We did exactly like how it was defined. At the end when we host it we are just getting big black box with red cross.

for integration in existing websites dvelopped by other companies, we integration forms with captcha in iframe.

Since several months (can't determine exact date), this isnt't working anymore.
If the form is contained in an iframe, the captcha image shows a red cross over a black background.

To test it, create a simple html page with an iframe to the current demo page :

<iframe src="http://vvson.net/Projects/en-US/Documentation/captcha-demo#content" width="100%" height="100%" />

Is there a way to make captcha work if page in contained in an iframe ?

P.S. Sorry for my poor english.

Using Captcha.MVC5 and works on some pages but not on the main login page for some reason. Only on this page I get the black box with the red "x" crossing the box. Any ideas on why it would NOT work on this view when it's set up exactly the same as the others? Dev tools shows no errors. The call to generate is successful but it shows the black box with red "x" in the Preview, e.g.,

Using the Refresh when this happens does show an error in Console, i.e.,
/DefaultCaptcha/Refresh 500 (Internal Server Error).

Can you please help as we don't want to go to a whole new captcha object.

Leave a Reply
* Bullet List
** Bullet List 2
# Number List
## Number List 2
{"Do not apply formatting"}
{code:language} code here {code:language}.
Supports: aspx c#, c#, c++, html, sql, xml