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?
The Html. Raw Helper Method is used to display HTML in Raw format i.e. without encoding in ASP.Net MVC Razor.
Raw method does not work and I have to use HttpUtility. HtmlDecode(EncodedContent) before I use Html.
Html. ActionLink() Helper is used to render an HTML link in a View. ActionLink() method actually links to a Controller action from inside a View.
For MVC2:
<%: MvcHtmlString.Create("<h2>Results</h2>") %>
Found here:
store and display html tags in MVC
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.
There is such helper now:
Html.Raw("<h2>Results</h2>")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With