I have allowed HTML on a model property like so:
Model
public class FooViewModel
{
[AllowHtml]
public string Description { get; set; }
}
View
@using (Html.BeginForm("EditDescription", "Foo", FormMethod.Post))
{
@Html.AntiForgeryToken();
<input type="hidden" value="@(Model != null && Model.Item1 != null ? Model.Item1 : string.Empty)" name="fooId" />
<p>
<textarea name="Description" cols="100" id="Description">
@(Model != null && Model.Item2 != null ? Model.Item2 : string.Empty)
</textarea>
</p>
<p><input type="submit" value="Submit" /></p>
}
@section Scripts {
@Scripts.Render("~/bundles/nicEdit")
<script type="text/javascript">
bkLib.onDomLoaded(function()
{
new nicEditor({fullPanel : true}).panelInstance('Description');
});
</script>
}
Controller
public class FooController
{
public ActionResult EditDescription(string fooId)
{
if (Request.HttpMethod == "POST")
{
using (var context = new ApplicationDbContext())
{
var foo = context.Foos
.SingleOrDefault(f => f.Id == fooId);
// I get the HttpRequestValidationException here
foo.Description = Request["Description"];
context.SaveChanges();
return RedirectToAction("MyProfile");
}
}
}
}
Still, I get a request validation exception. I even tried annotating the entire action method with ValidateInput(false)
since the View has only one field, which is the single property on the model, but I still keep getting the exception.
I cleared the ASP.NET temporary files and folders cache, cleaned and rebuilt my solution all to no avail.