zoukankan      html  css  js  c++  java
  • MVC5 您不能调用控制器“xx”上的操作方法“xx”,因为该方法是一种泛型方法

    在 MVC5 中当使用   routes.MapMvcAttributeRoutes() 添加路由属性是导致在控制器创建的泛型方法调用错误:

    Cannot call action method 'System.Collections.Generic.IEnumerable1[System.Web.Mvc.SelectListItem] GetSelectList[T](System.Collections.Generic.IEnumerable1[T], System.String, System.String, System.String, System.Object)' on controller 'PublicationSystem.Controllers.BaseController' because the action method is a generic method.
    Parameter name: methodInfo

    例如:

    public void AddArbet<T>(T bet, int userId)
            {
                string key = "APIFilterArbet" + userId + "";
                List<T> bets = GetArbets<T>(userId);
                if (bets != null)
                {
                    if (bets.Count > 50)
                    {
                        bets.Clear();
                    }
                    bets.Add(bet);
                    _cacheManager.Set(key, bets, 60);
                }
            }
    

      

    解决方法: 只需要把  public void AddArbet<T>(T bet, int userId) 把 public ->  protected 即可 ,可以了下MVC 控制器继承工作原理。

  • 相关阅读:
    3.3 直方图处理与函数绘图
    光头强
    考试代码模板
    【2015初赛】预备
    NOIP2018 模拟题
    NOIP2017 模拟赛
    【解题报告】树形DP入门
    【解题报告】区间DP
    【解题报告】树形背包
    二分刷题单
  • 原文地址:https://www.cnblogs.com/mschen/p/7158642.html
Copyright © 2011-2022 走看看