模型属性忽略 html 实体的验证
我想在数据库中输入html并将其显示为html。我这样编写视图模型:
public class TemplateVM
{
[HiddenInput(DisplayValue = false)]
public int TemplateId { get; set; }
public string Name { get; set; }
public string Content { get; set; }
}
属性 Content
应该能够接受 html。我该怎么做?现在,它会抛出以下错误:
test从客户端检测到潜在危险的 Request.Form 值 (Content="
我知道使用这是关于操作的,但我不希望它适用于每个属性。:
[ValidateInput(false)]
I want to input html in the database and also display it back as html. I wrote my view model like this:
public class TemplateVM
{
[HiddenInput(DisplayValue = false)]
public int TemplateId { get; set; }
public string Name { get; set; }
public string Content { get; set; }
}
the property Content
should be able to accept html. How can I do this? Right now, it throws the error of:
A potentially dangerous Request.Form value was detected from the client (Content="<p>test</p>").
I'm aware of using this on the action, but I dont want it to apply to every property.:
[ValidateInput(false)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您不要在整个模型上使用
ValidateInput
属性,而是在Content
属性上使用AllowHtml
属性:此属性仅适用于
Content
属性,而其他属性仍在验证中。Instead of using
ValidateInput
attribute on entire model, I suggest you useAllowHtml
attribute onContent
property:This attribute is only applied for
Content
property, while other properties are still validated.将
[ValidateInput(false)]
放在TemplateVM
之上。它将适用于所有属性。Put
[ValidateInput(false)]
on top ofTemplateVM
. It will apply to all properties.