我為公共 ActionResult 產品創建了視圖,我希望它顯示為 html 而不是文本
`<div class="grid product">
<div class="col-xs-12 col-md-7">
<div class="product-image">
<img src="~/Images/@Model.image">
</div>
</div>
<div class="col-xs-12 col-md-5">
<h1>@Model.ProductName</h1>
<h2>Price: @Model.price</h2>
<div class="description">
@Model.Detail > **It shows text and i want its content to be html**
</div>
</div>
</div>`
這就是它在@Model.Detail顯示的內容
[show on website][1]
[html code][2]
[1]: https://i.stack.imgur.com/PfGP0.png
And this is how it shows in the html file
[2]: https://i.stack.imgur.com/IOmzu.png
有沒有辦法讓我洗掉 " 以便 @Model.Detail 中的內容變成 html 代碼?
uj5u.com熱心網友回復:
默認情況下,輸出是由 ASP.NET 框架進行 HTML 編碼的。這是一件好事,因為編碼不當的輸出很容易導致XSS 漏洞。(如果允許用戶修改 HTML 內容,也會出現丑陋的錯誤和 UI 問題。)
如果這不是您關心的問題,并且您對內容的有效性充滿信心,您可以使用以下命令強制不對其進行編碼HtmlHelper.Raw:
<div class="description">
@Html.Raw(Model.Detail)
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/496131.html
標籤:html 网 asp.net-mvc
