Eminem Eminem - 3 months ago 22
ASP.NET (C#) Question

C# how do I include the following in HTML

I have a MVC website which uses razor syntax. I generate a table from values from a db.
In a table cell I have some text e.g.

This is some text

code

<td>
this is <b>some</b> text
</td>


Now I need a word to be bold. I have tried
<b>some</b>
but that is exactly how it appears on the web page. I need it to look like

This is some text

Answer

The only way this could be happening is if your <b>some</b> string is coming from a variable elsewhere in your code. Razor automatically escapes this for safety reasons, but you can force it to be rendered as-is with view helpers already available in Razor.

Use the Html.Raw() helper to render a string without sanitizing it.

<td>
    This is @Html.Raw(Model[i].QuestionText) text
</td>