Ultron
Ultron

Reputation: 1

How can i display asp.net html style?

I has create view for public ActionResult Product and I want it shows as html and not as text

`<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>`

and this is what it shows at @Model.Detail

[show on website][1]


[html code][2]



  [1]: https://i.sstatic.net/PfGP0.png

And this is how it shows in the html file

  [2]: https://i.sstatic.net/IOmzu.png

Is there a way for me to remove the " so that the content in @Model.Detail becomes html code?

Upvotes: 0

Views: 268

Answers (1)

David
David

Reputation: 218798

By default output is HTML-encoded by the ASP.NET Framework. This is a good thing because improperly encoded output can easily lead to XSS vulnerabilities. (As well as just ugly bugs and UI issues if users are allowed to modify HTML content.)

If this isn't a concern for you and you are confident of the validity of your content, you can force it to not be encoded by using HtmlHelper.Raw:

<div class="description">
    @Html.Raw(Model.Detail)
</div>

Upvotes: 1

Related Questions