Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Partial Methods with dynamic parameters

ASP.NET MVC 2

I'm trying to write a view whose generic parameter is dynamic, and then pass this dynamic model to a partial view

<%@ Page Title="" ..... Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

and then

<% Html.RenderPartial("MenuTabsPartial", Model); %>

but I'm getting the error

'System.Web.Mvc.HtmlHelper' has no applicable method named 'RenderPartial' but appears to have an extension method by that name ...

I am fully aware that extension methods cannot be dispatched with dynamic parameters.

My question is, is there some sort of MVC-specific work around?

This extension method has to be defined in a public static calss somewhere, right? Is it possible to invoke RenderPartial from there, like you can with linq:

Enumerable.Where(stringArray, s => s.StartsWith("Adam"));
like image 647
Adam Rackis Avatar asked Feb 17 '12 16:02

Adam Rackis


1 Answers

You can find RenderPartial in RenderPartialExtensions and RenderAction in ChildActionExtensions.

So to call these methods with a dynamic parameter, you'd do:

<% RenderPartialExtensions.RenderPartial(Html, "MenuTabsPartial", Model); %>

and

<% ChildActionExtensions.RenderAction(Html, "List", Model); %>
like image 181
John H Avatar answered Sep 19 '22 03:09

John H