2016-04-21 72 views
4

我有一个SQL表格,其中包含显示文本的HTML格式。ASP.Net MVC 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格式。任何人都可以帮助解决我遇到的问题吗?

回答

6

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

而不是

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

使用

@Html.Raw(item.Body) 

Reference

+0

谢谢你这工作:) – TerrorTot38

+0

@ TerrorTot38 ..你欢迎。 –