最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to write HTML syntax to view in ASP.NET Core - Stack Overflow

programmeradmin3浏览0评论

I have content which includes HTML tags, but when I write the value to the view, it encodes it and the HTML tags are messed up.

I've tried to use HtmlDecode, but same issue.

Code:

@WebUtility.HtmlDecode(img.Description)

Data:

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

Output (HTML):

<div class="details-wrap">
    <hr style="width:60%;" />

    dette er&lt;br /&gt;beskrivelse
</div>

I have content which includes HTML tags, but when I write the value to the view, it encodes it and the HTML tags are messed up.

I've tried to use HtmlDecode, but same issue.

Code:

@WebUtility.HtmlDecode(img.Description)

Data:

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

Output (HTML):

<div class="details-wrap">
    <hr style="width:60%;" />

    dette er&lt;br /&gt;beskrivelse
</div>
Share Improve this question asked Jan 19 at 17:46 SteinTechSteinTech 4,0684 gold badges43 silver badges89 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

To display the HTML-decoded description in an ASP.NET Core view, you can use @WebUtility.HtmlDecode to decode the HTML string contained in img.Description. Here's how you can write the syntax in a Razor view:

@using System.Net

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

HTML output:

<div>
    <h3>this is pic01</h3>
    <p>dette er<br />beskrivelse</p>
</div>
发布评论

评论列表(0)

  1. 暂无评论