代码之家  ›  专栏  ›  技术社区  ›  SteinTech

如何在ASP.NET中编写HTML语法进行查看。NET核心

  •  0
  • SteinTech  · 技术社区  · 10 月前

    我有包含HTML标签的内容,但当我将值写入视图时,它会对其进行编码,HTML标签会被弄乱。

    我尝试过使用HtmlDecode,但遇到了同样的问题。

    代码:

    @WebUtility.HtmlDecode(img.Description)
    

    数据:

    {
      "name": "pic1.jpg",
      "order": 2,
      "likes": 21,
      "title": "this is pic01",
      "description": "dette er<br />beskrivelse"
    }
    

    输出(HTML):

    <div class="details-wrap">
        <hr style="width:60%;" />
    
        dette er&lt;br /&gt;beskrivelse
    </div>
    
    1 回复  |  直到 10 月前
        1
  •  2
  •   Prolog Leodev    10 月前

    在ASP中显示HTML解码的描述。NET Core视图,您可以使用@WebUtility。HtmlDecode用于解码img中包含的HTML字符串。说明。以下是如何在Razor视图中编写语法:

    @using System.Net
    
    <div>
        <h3>@img.Title</h3>
        <p>@Html.Raw(WebUtility.HtmlDecode(img.Description))</p>
    </div>
    

    HTML输出:

    <div>
        <h3>this is pic01</h3>
        <p>dette er<br />beskrivelse</p>
    </div>
    
    推荐文章