ASP .NET MVC 1
I'd like to show a partial view base on a model, and I'd like that to have a fairly short command for that. So I saw a way of using both a HtmlHelper and a controller (And I'd use another controller for that, not the controller currently used).
But somehow it still gives an error, though I think the method starts to look as it should.
So what am I doing wrong? (If I call the method directly in the ASPX-page, it succeeds. But it should be possible to use a HtmlHelper for that).
public static void RenderPartialView(this HtmlHelper html, string action, string controller, object model)
{
var context = html.ViewContext;
RouteData rd = new RouteData(context.RouteData.Route, context.RouteData.RouteHandler);
rd.Values.Add("controller", controller);
rd.Values.Add("action", action);
rd.Values.Add("model", model);
IHttpHandler handler = new MvcHandler(new RequestContext(context.HttpContext, rd));
handler.ProcessRequest(System.Web.HttpContext.Current);
}
Part in the ASCX-page:
<% Html.RenderPartialView("Show", "Intro", Model.Intro); %>
Error given: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartialView' and no extension method 'RenderPartialView' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)