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

it2022-05-24  72

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

 

转载于:https://www.cnblogs.com/mschen/p/7158642.html

相关资源:数据结构—成绩单生成器

最新回复(0)