Asp.net mvc razor模板内的分析器错误
我正试图在我的项目中使用Captcha,但在下面的代码中出现了一个解析器错误…正在努力消除它Asp.net mvc razor模板内的分析器错误,asp.net-mvc,razor,visual-studio-2013,Asp.net Mvc,Razor,Visual Studio 2013,我正试图在我的项目中使用Captcha,但在下面的代码中出现了一个解析器错误…正在努力消除它 @{MvcCaptcha registrationCaptcha = CaptchaHelper.GetRegistrationCaptcha(); } @if (!registrationCaptcha.IsSolved) { <div class="form-group"> <div class="col-md-offset-4 col-md-8">
@{MvcCaptcha registrationCaptcha = CaptchaHelper.GetRegistrationCaptcha(); }
@if (!registrationCaptcha.IsSolved)
{
<div class="form-group">
<div class="col-md-offset-4 col-md-8">
@Html.Captcha(registrationCaptcha)
</div>
@Html.Label("Retype the code", new { @class = "col-md-4 control-label", @for = "CaptchaCode" })
<div class="col-md-8">
@Html.TextBox("CaptchaCode", null, new { @class = "form-control captchaVal" })
</div>
</div>
}
@{MvcCaptcha registrationCaptcha=captchaheloper.GetRegistrationCaptcha();}
@如果(!registrationCaptcha.IsResolved)
{
@Html.Captcha(注册验证码)
@Label(“重新键入代码”,新的{@class=“col-md-4控制标签”,@for=“CaptchaCode”})
@TextBox(“CaptchaCode”,null,新{@class=“form control captchaVal”})
}
解析器错误的原因是什么?设法纠正了它
MvcCaptcha registrationCaptcha = CaptchaHelper.GetRegistrationCaptcha();
if (!registrationCaptcha.IsSolved)
{
<div class="form-group">
<div class="col-md-offset-4 col-md-8">
@Html.Captcha(registrationCaptcha)
</div>
@Html.Label("Retype the code",
new { @class = "col-md-4 control-label", @for = "CaptchaCode" })
<div class="col-md-8">
@Html.TextBox("CaptchaCode", null,
new { @class = "form-control captchaVal" })
</div>
</div>
}
MvcCaptcha registrationCaptcha=captchaheloper.GetRegistrationCaptcha();
如果(!registrationCaptcha.IsResolved)
{
@Html.Captcha(注册验证码)
@Label(“重新键入代码”,
新的{@class=“col-md-4控制标签”,@for=“CaptchaCode”})
@文本框(“CaptchaCode”,null,
新的{@class=“form control captchaVal”})
}
请发布异常消息我确实更新了它,将“@if”更改为“if”仍然会出现错误。看起来您已经在一个razor代码块中了。尝试删除@
-justif(!registrationCaptcha.IsSolved)
{…`去掉@会给出以下消息解析器错误消息:“@”字符后出现意外的“{”。一旦进入代码块体(@if{},@{},等等),就不需要使用“@{”切换到代码。