6

How exactly do you get ReCaptcha work in MVC3 with razor? I tried "Install-Package microsoft-web-helpers" but still could not get it to work on my .cshtml razor page, it cannot find the type ReCaptcha. And, on http://nuget.org/List/Packages/microsoft-web-helpers someone left comment saying "This package currently works with WebMatrix only". While this article shows it may work http://www.dotnetcurry.com/ShowArticle.aspx?ID=611

Ray
  • 12,101
  • 27
  • 95
  • 137

4 Answers4

6

You might need to make the Microsoft.Web.Helpers namespace available to the views. In your Web.config (the one in your Views folder) add:

<namespaces>
    <!-- other namespaces here -->
    <add namespace="Microsoft.Web.Helpers"/>
</namespaces>

Then you can use the following helper in your view:

@ReCaptcha.Validate([public key])

If the namespaces setting doesn't work, you could try to add @using Microsoft.Web.Helpers statement on top of the view to see if that helps. If it does, you'll have to try and find out why the namespace setting in the web.config isn't working...

Community
  • 1
  • 1
Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101
  • Thanks Sergi, still not working, I installed the nuget pkg, but I suspect somehow it installed me the older 1.0 Microsoft.Web.Helpers intead of 1.1 and it just could not find it. – Ray Apr 14 '11 at 16:58
  • Then it should be as easy as uninstalling and reinstalling, or even update the package through the `Add Library Package Reference` dialog, shouldn't it? – Sergi Papaseit Apr 14 '11 at 17:01
  • I'm using the Pkg Mgr Console since my Add Lib Package Ref is not showing up. Anyway, even with the dll and setting in web.config, it is still not recognizing ReCaptcha for some reason – Ray Apr 14 '11 at 17:04
  • You could try adding a `@using Microsoft.Web.Helpers` on top of the view to see if that helps. If it does, you'll have to try and find out why the namespace setting in the web.config isn't working... – Sergi Papaseit Apr 14 '11 at 17:08
2

See this http://eglasius.blogspot.com/2010/10/adding-recaptcha-to-aspnet-mvc.html

Korayem
  • 12,108
  • 5
  • 69
  • 56
1

Might be too late to the party but I could not get any of the examples out there to work with MVC3. Microsoft's helpers does not appear to work either.

Finally downloaded the reCaptcha binary from google code for .net - http://code.google.com/p/recaptcha/downloads/list and created a custom razor Html helper.

Code is available on Github - https://github.com/clearinterface/MvcRecaptcha

Hope this helps.

Eric Lee
  • 712
  • 4
  • 5
-2

The answers above are not 100% complete so I wrote a tutorial that covers every single step.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Petras
  • 4,686
  • 14
  • 57
  • 89