Question

I seem to be hitting a logical contradiction. I have a view with...

</br> in the markup and when I load the page it shows a new line. Inspecting the source I can see a </br>.

Then I put @Html.Raw("</br>") and in the source I get &lt;/br&gt;

However all the documentation says that by default razor will html encode all strings. So why does Html.Raw show an encoded string instead?

Shouldn't it be the other way around?

Was it helpful?

Solution

</br> is incorrect, you probably meant <br/>.

This being said, here's how it works:

<br/> generates <br/>
@("<br/>") generates &lt;br/&gt;
@Html.Raw("<br/>") generates <br/>

The Html.Raw helper is used when you do not want to get HTML encoded output in the resulting HTML. By default the @ Razor function HTML encodes its argument.

OTHER TIPS

From W3schools (I know it ain't W3C official)

Differences Between HTML and XHTML

In HTML, the <br> tag has no end tag. In XHTML, the <br> tag must be properly closed, like this: <br />.

I don't know about razor it's @Html function but you don't need the '/' at all

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top