Public action method was not found on controller

拜拜、爱过 提交于 2019-12-01 05:26:12

问题


I have the following controller method:

public ActionResult GetResults(string viewToReturn, int resultsPerPage, 
          string classification = null, string sessionId = null, int? lastId= null)
{
               ...
}

Calling the method above via the following url:

http://localhost:63455/Home/GetResults?viewToReturn=grid&resultsPerPage=30

results in an exception thrown with this message:

A public action method 'GetResults' was not found on controller 'MyWebSite.Controllers.HomeController'.

and here is the RegisterRoutes:

......    
routes.MapRoute("Home", "home/{action}/{*qualifier}",
       new { controller = "Home", action = "Index", qualifier = UrlParameter.Optional });
......
routes.MapRoute("SearchTitle", "{*path}",
       new { controller = "Home", action = "SearchTitle", path = UrlParameter.Optional });

Why am I getting this error and how do I fix it? Thanks!


回答1:


I had the [HttpPost] attribute on the method. I could swear that I removed it earlier, but somehow after I took a break and came back, I saw it. After removing it, everything now works fine.



来源:https://stackoverflow.com/questions/16658020/public-action-method-was-not-found-on-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!