简体   繁体   English

如何在html中转换字符串? (asp.net)

[英]How to Convert string in html? (asp.net)

I have some code like 我有一些像

@{
      string result = "<div> text </div><br />";
}

and I want print content of this variable into some html 我想将此变量的内容打印到一些html中

<div id="seachResult2">
   Search results: @Server.HtmlDecode(result);
</div>

but it doesn't work. 但这不起作用。 I know about HtmlString class and it has ToHtmlString and ToString methods but I can't find something like string.ToHtml(). 我知道HtmlString类,它具有ToHtmlString和ToString方法,但是找不到string.ToHtml()之类的东西。

It is my first question here. 这是我的第一个问题。 I hope somebody will help me to solve this problem. 我希望有人能帮助我解决这个问题。

You could use: @Html.Raw(result) 您可以使用: @Html.Raw(result)

Or use an MvcHtmlString instead of the normal string. 或使用MvcHtmlString代替普通字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM