skip to Main Content

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:

&lt;span style="color: red; font-weight: bold;"&gt;Authorized.&lt;/span&gt;

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

enter image description here

But what I see is this picture

enter image description here

2

Answers


  1. If you have a div in html, you can do this way:

     string message = "<span style="color: red; font-weight: bold;">Authorized.</span>";
     idofyourdiv.InnerHtml = message;
    
    Login or Signup to reply.
  2. 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));

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search