我被卡在了22上。我有一个问题,这两个属性不能一起工作。如果我从控制器操作中删除[CaptchaVerify]
属性,我的属性上的[AllowHtml]
属性将起作用。如何使[AllowHtml]和[CaptchaVerify]一起工作?
我得到
从 客户
异常被检测到有潜在危险的Request.Form值。
我该如何解决这个问题?
这里是我的属性,应该允许HTML:
[AllowHtml]
[Required(ErrorMessage = "Please enter a comment.")]
public string CommentText
{
get; set;
}
我的视图看起来像这样(我截断它这个例子):
@using CaptchaMvc.HtmlHelpers
@using (Html.BeginForm("Article", "Home", FormMethod.Post))
{
@Html.TextBoxFor(m => m.CommentText, new { @class = "form-control" })
@Html.Captcha("Refresh", "Enter the phrase shown above", 4, "Captcha image is required.", false)
<input type="submit" value="Post" />
}
我的控制器看起来像这个:
[HttpPost]
[CaptchaMvc.Attributes.CaptchaVerify("Captcha is not valid")]
public async Task<ActionResult> Article(ArticleModel model)
{
// Check the captcha.
if (ModelState["CaptchaInputText"] != null && ModelState["CaptchaInputText"].Errors.Count > 0)
{
ViewBag.CaptchaError = "Please fill in the text above";
}
// Rest of my action
}
非常好。完美的作品!谢谢! – Noobie3001