I want to include the following HTML code in my C# code:
<span style="color: red; font-weight: bold;">Authorized.</span>
However, when I include it in my C# code as is, it’s getting transformed into the following:
<span style="color: red; font-weight: bold;">Authorized.</span>
When I try to display this message on the C# side, I’m getting this result: it’s changing the < sign to "&l-t;" instead.
That’s why I can’t display it in red and bold on the screen; I’m just printing a sentence with a tag as plain text.
In c# code
string message = "<span style="color: red; font-weight: bold;">Authorized.</span>";
BaseMessage = new BaseMessage()
{
Kod = "1",
Mesaj = message,
Tip = MesajTipi.Hata,
Yer = "X"
};
The picture I want to see is this
But what I see is this picture
2
Answers
If you have a div in html, you can do this way:
If your html is not encoded you can use @Html.Raw(message).
If it is encoded you have to do the following :
Html.Raw(HttpUtility.HtmlDecode(message));