+3  A: 

My guess is to encourage you to use System.Web.HtmlString instead. But yes, I've wondered this myself and I've written a duplicate ToMvcHtmlString extension in my own helpers.

MvcHtmlString is, IIRC, just their compatibility fix so MVC 2 can work on both .NET 3.5 and 4 - but even then it'd be useful to use in your own code for that.

Rup
+1  A: 

Does this solve your problem?

public static MvcHtmlString SuperDenizControl(this HtmlHelper html)
{
    var builder = new TagBuilder("select");
    //blah blah blah amazing control
    var control = builder.ToString();
    return MvcHtmlString.Create(control);
}
BritishDeveloper
It's not a problem, I'm just curious to know why. Cool method name, by the way! :)
Deniz Dogan
A: 

I thought I'd post an easy workaround for those that might be looking for one and stumble upon this question.

While ToMvcHtmlString is internal, it is pretty easy to bypass the need to use it uses public methods:

From the MVC source:

internal MvcHtmlString ToMvcHtmlString(TagRenderMode renderMode) {
    return MvcHtmlString.Create(ToString(renderMode));
}

Both MvcHtmlString.Create and TagBuilder.ToString are public so just replace

return tagBuilder.ToMvcHtmlString(TagRenderMode.Normal);

with

return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal));

and you are good to go! Works great for me. Not sure why they even bothered to make a separate internal method.

Bradley Mountford