If you are working with ASP.NET MVC 3 and the new Razor View Engine, you probably stumbled upon the fact that with Razor everyting is HTML encoded and the concept of Html Encoding Nuggets don't exist in Razor. This is actually a good thing as there is a lot of confusion about when and when not to use those nuggets in the WebForms View Engine. For security reasons you really always want everything HTML encoded and want to make it an extra explict effort to not HTML encode something.

Therefore with the Razor View Engine when you pass a string to the response stream that includes HTML tags, the tags will be HTML encoded and show up in the browser as such:

 

Html.Raw   One_WEB

 

As discussed in the previous HtmlString and IHtmlString tutorial, you can get around this HTML encoding by wrapping the string with the class HtmlString. You can go ahead and manually construct your own HtmlString or use a built in HtmlHelper in ASP.NET MVC 3, called Html.Raw, that does the exact same thing.

 

Html.Raw   One_IT_02

 

In this case the HTML tags won't be encoded, but instead become part of the HTML in the source of the page.

In conclusion, now that everything associated with the Razor View Engine in ASP.NET MVC 3 and ASP.NET Web Pages is HTML encoded when sent to the browser, you need to use HtmlString or another implementation of IHtmlString that allows you to skip HTML encoding when appropriate. In most cases, you will find HTML Helpers, like Html.Raw, that use HtmlString behind the scenes for you.

Hope this helps.

David Hayden