gpt4 book ai didi

c# - ViewModel 中的 HTML.Raw 等效 DataAnnotation

转载 作者:行者123 更新时间:2023-11-30 14:57:30 25 4
gpt4 key购买 nike

有没有等同于@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com