Search code examples
asp.netasp.net-mvchtml-encode

ASP.NET MVC @Html.Raw() not working


I have this line of code here in my view

I have this string @Model.inventory.overview and it has — in it.

When I try to use it so it will display the special html character it shows up as the text —

@Html.Raw(Model.inventory.overview)

and

@MvcHtmlString.Create(Model.inventory.overview)

This is what @Model.inventory.overview is

Lorem ipsum dolor sit—amet, consectetur adipiscing elit. Mauris eget feugiat nibh. Fusce rhoncus ex et nunc fringilla, ut fermentum tortor volutpat. Praesent mollis efficitur magna auctor sollicitudin. Morbi pulvinar, justo ut efficitur rutrum, dui metus varius magna, vitae molestie leo elit vel turpis. Nullam quis ipsum nec erat maximus dictum sit amet sed ligula. Vestibulum tincidunt dolor non—justo accumsan, eu euismod neque rutrum. Donec in lacinia est.

I have also tried the following:

@Html.Raw(HttpUtility.HtmlDecode(@model.ContentBody));

Still not working.


Solution

  • @Html.Raw(Html.Encode(Model.inventory.overview)) was the solution after all.

    I looked at W3C Html ASCII characters list and had a suspicion — wasn't "exactly" a ASCII character, so I found this site soon after. Glad I was helpful.