无法显示带有跨度html标签的图标绑定

时间:2019-07-09 11:54:56

标签: html asp.net

我有一个字符串消息,我想用c#在asp.net中显示图标以及字符串消息。页面加载后,它显示的是正常字符串而不是图标

  public string InfoMessage;
  InfoMessage = "Please choose at least one image type from the settings panel. You can configure this gadget by pressing the <span class='ui-icon ui-icon-inline ui-icon-wrench'></span>icon at the top of this gadget.";

我希望扳手图标可见,但它正在显示

1 个答案:

答案 0 :(得分:0)

对于ASP.NET Webforms应用程序。试试这个:

html代码:

<span id="webcontent" runat="server">
 </span>

后面的代码:

  webcontent.InnerHtml = InfoMessage;

对于ASP.NET MVC App,请在下面使用:

控制器:

  string InfoMessage;
        InfoMessage = "Please choose at least one image type from the settings panel. You can configure this gadget by pressing the <span class='ui-icon ui-icon-inline ui-icon-wrench'></span>icon at the top of this gadget.";
        ViewBag.Message = InfoMessage;

查看:

<span>@Html.Raw(ViewBag.Message)</span>