I'm stuck on a catch 22 here. I have an issue where these two attributes are not working together. The [AllowHtml]
attribute on my property works if I remove the [CaptchaVerify]
attribute from the controller action.
I'm getting the
A potentially dangerous Request.Form value was detected from the client
exception.
How can I get round this?
Here's my property that should allow html:
[AllowHtml]
[Required(ErrorMessage = "Please enter a comment.")]
public string CommentText
{
get; set;
}
My View looks like this (I've truncated it for this example):
@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" />
}
My Controller looks like this:
[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
}