I am trying to add recaptcha in my user registration page in my MVC 4 application. I have added recaptcha v3 through nuget package console. However I am getting error when trying to add it in the views.
The namespaces has been registered in the web.config
When I try to add the recaptcha with @using directive, I am getting error that the namespace could not be found. The same namespace is working good in the controllers but not in the views.
Below is my code for View
@using Recaptcha
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model Insightsv1.Models.UserRegister
<div class="container">
<div class="row">
<div class="container">
<div class="row">
<div class="row font-bold">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item"> </li>
<li class="breadcrumb-item active" aria-current="page"> User registration</li>
</ol>
</nav>
</div>
</div>
<hr />
<br />
<div class="col-5">
@using (Ajax.BeginForm("UserRegistration", "Home", _objAjaxOptions))
{
@Html.AntiForgeryToken()
<div class="row row-no-gutters">
<div class="col">
<span class=".align-items-center">Username: </span>
</div>
<div class="col">
@Html.TextBoxFor(model => model.UserName, new { @class = "form-control col-30", type = "email", required = "", id = "txtUsername", autocomplete = "off", placeholder = "Email address", width = "400px" })
<span class="text-danger"> @Html.ValidationMessageFor(model => model.UserName)</span>
</div>
</div>
<br />
<div class="row">
<div class="col">Firstname: </div>
<div class="col">
@Html.TextBoxFor(model => model.FirstName, new { @class = "form-control col-30", required = "", id = "txtFirstName", autocomplete = "off", placeholder = "First Name", width = "400px" })
<span class="text-danger">@Html.ValidationMessageFor(model => model.FirstName)</span>
</div>
</div>
<br />
<div class="row">
<div class="col">Lastname: </div>
<div class="col">
@Html.TextBoxFor(model => model.LastName, new { @class = "form-control col-30", required = "", id = "txtLastName", autocomplete = "off", placeholder = "Last Name", width = "400px" })
<span class="text-danger">@Html.ValidationMessageFor(model => model.LastName)</span>
</div>
</div>
<br />
<div class="row">
<div class="col">Lastname: </div>
<div class="col">
@Html.Raw(Html.GenerateCaptcha("captcha", "clean"))
@Html.ValidationMessage("captcha")
</div>
</div>
<br />
<div class="row">
<div class="col"></div>
<div class="col-8">
<input type="submit" value="Register New User" class="btn btn-primary" />
</div>
</div>
}
</div>
<br />
</div>
</div>
</div>
Also the below line is throwing the error as HtmlHelper does not contain a definition for GenerateCaptcha and no accessible extension method 'GenerateCaptcha' accepting a first argument of type HtmlHelper could be found.
@Html.Raw(Html.GenerateCaptcha("captcha", "clean"))
I have added the model UserRegister with
public string Recaptcha {get;set;}
I dont have any idea why i am not able to get the solution. If anyone can help me it would be great. Also is there any other implementation of recaptcha other then this?
Thanks for your help.
question from:
https://stackoverflow.com/questions/65882080/unable-to-add-recaptcha-in-the-cshtml-namespace-not-available-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…