Home > front end >  How can i display asp.net html style?
How can i display asp.net html style?

Time:06-25

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

`<div >
     <div >
         <div >
             <img src="~/Images/@Model.image">
         </div>
     </div>
     <div >
         <h1>@Model.ProductName</h1>
         <h2>Price: @Model.price</h2>
         <div >
             @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.stack.imgur.com/PfGP0.png

And this is how it shows in the html file

  [2]: https://i.stack.imgur.com/IOmzu.png

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

CodePudding user response:

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 >
    @Html.Raw(Model.Detail)
</div>
  • Related