Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 812403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:11:57+00:00 2026-05-15T01:11:57+00:00

Cannot call action method ‘System.Web.Mvc.PartialViewResult FooT’ on controller ‘Controller’ because the action method is

  • 0

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
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:11:58+00:00Added an answer on May 15, 2026 at 1:11 am

    The code that throws that is inside the default ActionDescriptor:

        internal static string VerifyActionMethodIsCallable(MethodInfo methodInfo) {
            // we can't call instance methods where the 'this' parameter is a type other than ControllerBase
            if (!methodInfo.IsStatic && !typeof(ControllerBase).IsAssignableFrom(methodInfo.ReflectedType)) {
                return String.Format(CultureInfo.CurrentUICulture, MvcResources.ReflectedActionDescriptor_CannotCallInstanceMethodOnNonControllerType,
                    methodInfo, methodInfo.ReflectedType.FullName);
            }
    
            // we can't call methods with open generic type parameters
            if (methodInfo.ContainsGenericParameters) {
                return String.Format(CultureInfo.CurrentUICulture, MvcResources.ReflectedActionDescriptor_CannotCallOpenGenericMethods,
                    methodInfo, methodInfo.ReflectedType.FullName);
            }
    
            // we can't call methods with ref/out parameters
            ParameterInfo[] parameterInfos = methodInfo.GetParameters();
            foreach (ParameterInfo parameterInfo in parameterInfos) {
                if (parameterInfo.IsOut || parameterInfo.ParameterType.IsByRef) {
                    return String.Format(CultureInfo.CurrentUICulture, MvcResources.ReflectedActionDescriptor_CannotCallMethodsWithOutOrRefParameters,
                        methodInfo, methodInfo.ReflectedType.FullName, parameterInfo);
                }
            }
    
            // we can call this method
            return null;
        }
    

    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.

    public class GenericControllerFactory : DefaultControllerFactory
    {
        protected override Type GetControllerType(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            //the generic type parameter doesn't matter here
            if (controllerName.EndsWith("Co"))//assuming we don't have any other generic controllers here
                return typeof(GenericController<>);
    
            return base.GetControllerType(requestContext, controllerName);
    
            throw new InvalidOperationException("Generic Factory wasn't able to resolve the controller type");
        }
    
        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            //are we asking for the generic controller?
            if (requestContext.RouteData.Values.ContainsKey("modelType"))
            {
                string typeName = requestContext.RouteData.Values["modelType"].ToString();
                //magic time
                return GetGenericControllerInstance(typeName, requestContext);
            }
    
            if (!typeof(IController).IsAssignableFrom(controllerType))
                throw new ArgumentException(string.Format("Type requested is not a controller: {0}",controllerType.Name),"controllerType");
    
            return base.GetControllerInstance(requestContext, controllerType);
        } 
    
        /// <summary>
        /// Returns the a generic IController tied to the typeName requested.  
        /// Since we only have a single generic controller the type is hardcoded for now
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        private IController GetGenericControllerInstance(string typeName, RequestContext requestContext)
        {
            var actionName = requestContext.RouteData.Values["action"];
    
            //try and resolve a custom view model
    
            Type actionModelType = Type.GetType("Brainnom.Web.Models." + typeName + actionName + "ViewModel, Brainnom.Web", false, true) ?? 
                Type.GetType("Brainnom.Web.Models." + typeName + ",Brainnom.Web", false, true);
    
            Type controllerType = typeof(GenericController<>).MakeGenericType(actionModelType);
    
            var controllerBase = Activator.CreateInstance(controllerType, new object[0] {}) as IController;
    
            return controllerBase;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 505k
  • Answers 505k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Okay problem solved. Solution was to use: <h:outputStylesheet name"css/default.css"/> <h:outputStylesheet… May 16, 2026 at 3:30 pm
  • Editorial Team
    Editorial Team added an answer Perhaps you need a compound foreign key that combines Status_Id… May 16, 2026 at 3:30 pm
  • Editorial Team
    Editorial Team added an answer select reverse('abcdef') ------ fedcba (1 row(s) affected) May 16, 2026 at 3:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

i cannot seem to get observe_form to call a particular action i have a
I need to run a Controller Action from my Console Application that reference to
See the four lines in the Go() method below: delegate void Action<T>(T arg); delegate
Using a technique I found in one of the recent ASP.NET MVC books, I
For the life of me, I cannot get the SqlProfileProvider to work in an
In my ASP.NET MVC app, I have an interface which acts as the template
This call // this._cfg is an NHibernate Configuration instance this._sessionFactory = this._cfg.BuildSessionFactory(); Gives me
I cannot figure this out. The workflow of passing IEnumerable<T> (T is some my
My previous for the same problem , Now, I am in a same situation
I have a model similar to this: public class myModel { public ClassA ObjectA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.