Search code examples
asp.net-mvcrazorinline-if

Can I write an inline if with HTML content?


I want to write something like:

@( checkCondition ? "<span class='label'>Right!</span>" : "")

But it is showing the source code instead the HTML, there is a easy way to do this?

Thank you!


Solution

  • You can use @Html.Raw(mystring) method like this:

    @( checkCondition ? Html.Raw("<span class='label'>Right!</span>") : Html.Raw(""))