views:

386

answers:

1

Is there an Html helper that simply accepts and returns raw html? Rather than do something ugly like this:

<% if (Model.Results.Count > 0) { %><h2>Results</h2><% } %>

I'd like to do something like this:

 <% if (Model.Results.Count > 0) { Html.RawHtml("<h2>Results</h2>") } %>

Not a whole lot cleaner, but I think it's a bit of an improvement. Does something like that exist? Or is there perhaps a better alternative to output raw html from within those escape characters than using Html helpers?

+2  A: 

Response.Write should work. (Although maybe it's kind of taking a step back!) You should be able to create an extension method to do it. And maybe instead of using HTML string, you might want to build your markup in code using the TagBuilder.

Maxwell Troy Milton King