How do I correctly Re-render a Recaptcha in ASP.NET MVC 2 after an AJAX POST

天涯浪子 提交于 2019-12-04 13:30:20

Figured out a solution to this.

I completely removed the client side rendering of the Captcha with the HTML Helper.

Instead, the Filter stays in place on the server side for doing the ModelState validation etc...

And the client side rendering is all done using the ReCaptcha AJAX Api's from http://recaptcha.net/fastcgi/demo/ajax and http://api.recaptcha.net/js/recaptcha_ajax.js

Everytime the partial post occurs, the captcha disappears, everytime it completes, the OnComplete script recreates it.

I assume The Html.CreateRecaptcha() extension creates a <div> or something that the scripts update with the captcha image. Shouldn't the Recaptcha.create() function pass 'recaptcha' (the id of the element) instead of 'blahCaptcha' (the name of the td)?

Take a look at the HTML produced by Html.CreateRecaptcha and try referring to the id of the element created by that extension instead of the id of the containing td.

I found this AJAX implementation very useful. http://www.darksideofthecarton.com/2008/12/15/validating-recaptcha-jquery-ajax/

I applied the same solution in my MVC code that based on this article:

http://devlicio.us/blogs/derik_whittaker/archive/2008/12/02/using-recaptcha-with-asp-net-mvc.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!