I have integrated the BotDetect Captcha in to my ASP.NET MVC form and I can not get the validation message to display when the user enters the incorrect Captcha value.
What do I need to change to get the validation message to display?
Edit - I added the Html.BeginForm
portion of the view to indicate that the post back is going to a different action in the controller.
Source Code - View
@using(Html.BeginForm("Create", "Contact", FormMethod.Post, new { enctype = 'multipart/form-data' }))
{
@{
MvcCaptcha contactCaptcha = new MvcCaptcha("ContactCaptcha");
contactCaptcha.UserInputID = "ContactCaptchaCode";
}
To prevent spam, we utilize a verification code system. Please enter the code as it is shown in the box below.<br />
@Html.Captcha(contactCaptcha)<br />
Code:<br />
@Html.TextBox("ContactCaptchaCode", string.Empty, new { @class = "form- control", @style = "width: 200px" })
<div class="row">
<div class="col-sm-12" style="text-align: right">
<input type="submit" value="Send" class="btn-default" />
@Html.ValidationMessage("ContactCaptchaCode", new { @class = "text-danger" })
</div>
</div>
}
Source Code - Controller
[HttpPost]
[AllowAnonymous]
[CaptchaValidation("ContactCaptchaCode", "ContactCaptcha", "Please enter the correct CAPTCHA code.")]
public ActionResult Create(Models.Contact formContact)
{
if(ModelState.IsValid)
{
//do stuff here is correct captcha value
}
}