Can we make all HtmlHelper methods to return an MvcHtmlString type?

Sep 25, 2010 at 8:38 AM

Razor syntax automatically encodes any results returned from methods.

This means that all helper methods that return a String type will be encoded so that the user will see actual HTML tags on the web page.

To make MvcSiteMap compatible with Razor syntax, all our helper methods must be altered to return a type of MvcHtmlString instead.

This should be a simple change.

Instead of:

return "abc";

You write:

return MvcHtmlString.Create("abc");