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?
BotDetect CAPTCHA Generator protects ASP.NET/Core forms from spam postings. The Captcha protection is available on.NET/Core for jQuery, Angular & React frontends and ASP.NET MVC1-6, WebForms & WebPages backends. It works in China; doesn't stalk; nor does it slurp your form-data - think: GDPR & LGPD! 19 rows BotDetect CAPTCHA Generator protects ASP.NET/Core forms from spam postings.
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
Source Code - Controller
Michael Kniskern
Michael KniskernMichael Kniskern
12.7k61 gold badges150 silver badges216 bronze badges
1 Answer
you have to add
!ModelState.IsValid
if false
then return to the view because in your code if model is invalid do nothing and thats not how validation works. so do something like this
now if you place a break point you will see
ModelState
will have keys
and values
if any validation fails and when you do return view(formContact);
it will return to the view with validation messages and it will match key and display the error message e.g let suppose i have
if validation fails for this property
UsmanUsman
modelstate
will have key=ContactCaptchaCode
and value=Please enter the correct CAPTCHA code.
3,8202 gold badges11 silver badges28 bronze badges
![Botdetect Botdetect](http://iplanet-public.sharepoint.com/SiteAssets/Pages/botdetect-asp-net-web/botdetect-asp-net-web_UI01.jpg)