【问题标题】:ASP.Net MVC SQL Formatting HTML [duplicate]ASP.Net MVC SQL 格式化 HTML [重复]
【发布时间】:2016-08-14 08:31:25
【问题描述】:

我有一个 SQL 表,其中包含显示文本的 HTML 格式。

<strong>What Is EDI ?</strong><p>EDI is a method for communicating electronically with trading partners based upon standards.</p>

在我的 MVC 应用程序中,下面有一个 index.cshtml 页面:

<h2>Index</h2>
<table>
    <tr>
        <th> @Html.DisplayNameFor(model => model.Body)</th>
        <th></th>
    </tr>
@foreach (var item in Model) {
    <tr>
        <td>@Html.DisplayFor(modelItem => item.Body)</td>
    </tr>
}
</table>

问题是文本显示正常,没有 HTML 格式。任何人都可以帮助解决我遇到的问题吗?

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor


    【解决方案1】:

    为此,您必须使用@Html.Raw()

    代替

    @Html.DisplayFor(modelItem => item.Body)
    

    使用

    @Html.Raw(item.Body)
    

    Reference.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 2013-02-12
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      相关资源
      最近更新 更多