ASP.NET MVC Using Render Partial from Within an Html Helper

Because this question, although old and marked answered, showed up in google, I'm going to give a different answer.

In asp.net mvc 2 and 3, there's an Html.Partial(...) method that works like RenderPartial but returns the partial view as a string instead of rendering it directly.

Your example thus becomes:

//using System.Web.Mvc.Html;
public static string MyHelper(this HtmlHelper helper)
{
    StringBuilder builder = new StringBuilder();
    builder.Append("Hi There");
    builder.Append(helper.Partial("MyPartialView"));
    builder.Append("Bye!");
    return builder.ToString();
}

Tags:

Asp.Net Mvc