1

I am using ASP.NET MVC, when I want to use the tag in @Html.Raw, this tag does not appear in the desired <div>.

As shown here:

<div class="mt-4 current-cursor">
    @Html.Raw("<strong>OKK</strong> <p><ul><li style='font-size:18px;'>1.Test1</li><li>2.Test2</li></p>")
</div>

The result that it displays for me is as below, that is, it does not recognize the <strong> tag at all.

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Hmlt.Raw doesn't "recognize" anything, it just emits the text as is. Are you sure your code isn't applying any unexpected styles to that tag? You can use your browser's Developer Tools to inspect any element in the final HTML page and see what styles are applied, where each attribute came from and if multiple styles are applied, what overrode what. – Panagiotis Kanavos Jul 26 '22 at 11:57
  • Just in the snippet you posted, `mt-4 current-cursor` applies to *all* tags inside that `div`. What is `current-cursor`? That's not a Bootstrap class – Panagiotis Kanavos Jul 26 '22 at 12:00

1 Answers1

1

Html.Raw does not interpret anything at all. It just spews the given string unencoded into the output docuument.

So if it doesn't look right in your case, possible you have some CSS in that page that causes it to look as it does. You could use F12 (Developer Tools, depending on your browser) to inspect the "OKK" for details.

BTW, the other tags in your example also look wrong (which could also be an issue given existing CSS in the page).

In my case, for example, using some (other) arbitrary styles, your code looks like this:

enter image description here

Christian.K
  • 47,778
  • 10
  • 99
  • 143