C# 在控制器上找不到公共操作方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16658020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Public action method was not found on controller
提问by Barka
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'.
在控制器“MyWebSite.Controllers.HomeController”上找不到公共操作方法“GetResults”。
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!
为什么我会收到此错误以及如何修复它?谢谢!
采纳答案by Barka
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.
我在方法上有 [HttpPost] 属性。我可以发誓我早些时候把它删除了,但不知何故,在我休息一下回来后,我看到了它。删除后,现在一切正常。

