【发布时间】:2020-04-11 11:30:12
【问题描述】:
我的 ViewModel / Action / Controller 采用以下形式:
[HttpPost, ValidateInput(false)]
public ActionResult TheActionMethod(TheViewModel aViewModelVariable)
{
if (ModelState.IsValid)
{
//Do the things
return AnActionThatListsAllItemsOfSimilarTypeAndGivesSuccessMessage(); //Can get here
}
else
{
//Do other things
}
return View(aViewModelVariable); //Error occurs if this line executes
}
而我的视图模型的形式为:
[Display(Name = "Does not allow HTML")]
public string AFieldThatDoesntAllowHtml{ get; set; }
[Required]
[Display(Name = "Allows HTML")]
[AllowHtml]
public string AFieldThatAllowsHtml{ get; set; }
我可以很好地提交,假设一切都验证并保存等。 如果 !ModelState.isValid 出现问题,并且代码到达 return View(aViewModelVariable);我总会得到:
System.Web.HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (AFieldThatAllowsHtml="<div>SomeText That was entered...")
我希望不用解决这个问题
<httpRuntime requestValidationMode="2.0" />
我也希望能够在没有 ValidateInput(false) 的情况下执行此操作
【问题讨论】:
标签: c# razor asp.net-mvc-5