Cannot call action method ‘System.Web.Mvc.PartialViewResult FooT’ on controller ‘Controller’ because the action method is a generic method
<% Html.RenderAction("Foo", model = Model}); %>
Is there a workaround for this limitation on ASP MVC 2? I would really prefer to use a generic. The workaround that I have come up with is to change the model type to be an object. It works, but is not preferred:
public PartialViewResult Foo<T>(T model) where T : class
{
// do stuff
}
The code that throws that is inside the default ActionDescriptor:
Because the code is calling “methodInfo.ContainsGenericParameters” I don’t think there is a way to override this behavior without creating your own ActionDescriptor. From glancing at the source code this seems non-trivial.
Another option is to make your controller class generic and create a custom generic controller factory. I have some experimental code that creates a generic controller. Its hacky but its just a personal experiment.