问题
In a View
in ASP.NET MVC
, I need to type following line of text:
"< h t m l > This is how you escape an HTML tag in Razor < / h t m l >"
Please remove spaces from < h t m l > to consider it a proper html tag.
How do I accomplish it? All answers are welcome.
回答1:
Try this.
@{ var myHtmlString = new HtmlString("<html> This is how you escape an HTML tag in Razor </html>");}
@Html.Encode(myHtmlString)
Prints
Another Simple Way is :
@Html.Encode(Html.Raw("<html> This is how you escape an HTML tag in Razor </html>"));
gives same output as above.
来源:https://stackoverflow.com/questions/45089555/how-to-escape-an-html-tag-in-razor