有没有等同于@Html.Raw(Model.Property)
的注解在 ViewModel 中?
我正在尝试使用 [DisplayFormat(HtmlEncode=false)]
未能成功创建 HTML 标记(<b>
、<span>
),而是将其显示为文本。
最佳答案
您可以使用 UIHint
通过创建一个模板 Views\Shared\DisplayTemplates\Html.cshtml
来做到这一点:
@model string
@Html.Raw(Model)
然后在你的模型上:
[UIHint("Html")]
public string MyHtml {get; set;}
这可以在所有其他 View 中输出为:
@Html.DisplayFor(m => m.MyHtml)
关于c# - ViewModel 中的 HTML.Raw 等效 DataAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20703242/