4
我有一个C#MVC4项目这个类:MVC4 AllowHtml不解释工作<字符串,字符串>
public class SaveModel
{
....
[AllowHtml]
public string BodyHtml { get; set; }
[AllowHtml]
public Dictionary<string, string> AdditionalTemplate { get; set; }
}
一个控制器的动作看起来像这样
public ActionResult SaveTemplate(SaveModel model)
{
....
}
的BodyHtml工作正常,但由于某种原因AllowHtml不会对字典工作,我得到这样的错误:
A potentially dangerous Request.Form value was detected from
the client (additionalTemplate[0].value="<tr>..."
有没有什么办法可以解决它,除了通过在我的操作中放置[ValidateInput(false)]来禁用整个请求的验证?
[ValidateInput(false)]
public ActionResult SaveTemplate(SaveModel model)
{
....
}
你没有显示你的观点是什么样子,但你可以使用'@ Html.Raw'。这似乎不值得发布为*答案*,但它阻止了视图HTML编码你的字符串。 – James
我也有这个问题,还没有找到解决方法。 – vkapadia