views:

114

answers:

1

@ in asp.net mvc 3 preview 1 automaticly encodes html, is there an alternative way to let there be html?

think of this scenario:

@view.BestSitesEver.Replace("stackoverflow", "<h1>StackOverflow</h1>")

That would just print out: <h1>stackoverflow</h1>

+5  A: 

You can use this

@MvcHtmlString.Create(site.Replace("stackoverflow", "<h1>stackoverflow</h1>"))

This will output the html string without encoding

@(new HtmlString(site.Replace("stackoverflow", "<h1>stackoverflow</h1>")))

And with Erik Porter's comment

BuildStarted
As of MVC 3 you don't need to use MvcHtmlString anymore. @(new HtmlString("<h1>StackOverflow</h1>")) will work just fine. Any implementation of IHtmlString will work though. We're considering a helper or shortcut that would create the new HtmlString for you in the future.
Erik Porter