本文介绍了如何在Razor中转义html标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ASP.NET MVC
中的View
中,我需要键入以下文本行:
In a View
in ASP.NET MVC
, I need to type following line of text:
< h t m l>这就是您如何在Razor</h t m l>"中转义HTML标记的方法
"< h t m l > This is how you escape an HTML tag in Razor < / h t m l >"
请从<中删除空格. h t m l>认为它是正确的html标签.
Please remove spaces from < h t m l > to consider it a proper html tag.
我该如何完成?欢迎所有答案.
How do I accomplish it? All answers are welcome.
推荐答案
尝试一下.
@{ var myHtmlString = new HtmlString("<html> This is how you escape an HTML tag in Razor </html>");}
@Html.Encode(myHtmlString)
打印
另一种简单的方法是:
@Html.Encode(Html.Raw("<html> This is how you escape an HTML tag in Razor </html>"));
提供与上述相同的输出.
gives same output as above.
这篇关于如何在Razor中转义html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!