ASP.MVC Html助手格式化文本

时间:2018-04-01 20:03:47

标签: asp.net-mvc razor html-helper

我的字符串是:

 string title = "CaSiO<sub>3</sub> perovskite in diamond indicates the recycling of oceanic crust into the lower mantle."

我使用了@ Html.Raw(标题)并获得了

CaSiO<sub>3</sub> perovskite in diamond indicates the recycling of oceanic crust into the lower mantle.

如何在视图中将其打印为:

钻石中的CaSiO 3 钙钛矿表明海洋地壳向下地幔的再循环。

1 个答案:

答案 0 :(得分:2)

@Html.Raw(WebUtility.HtmlDecode(title))将以您想要的格式显示字符串。

(但为什么首先以这种方式定义字符串?为什么不用<sub></sub>定义它然后只使用@Html.Raw()?)