码迷,mamicode.com
首页 > Web开发 > 详细

MVC5 您不能调用控制器“xx”上的操作方法“xx”,因为该方法是一种泛型方法

时间:2017-07-13 10:39:57      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:method   get   system   out   enum   use   public   不能   clear   

在 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 控制器继承工作原理。

 

MVC5 您不能调用控制器“xx”上的操作方法“xx”,因为该方法是一种泛型方法

标签:method   get   system   out   enum   use   public   不能   clear   

原文地址:http://www.cnblogs.com/mschen/p/7158642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!