公共行动方法没有找到控制器 [英] Public action method was not found on controller

查看:360
本文介绍了公共行动方法没有找到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下控制器方法:

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:

一个公共行动方法GetResults没有控制器
'MyWebSite.Controllers.HomeController'找到。

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

和这里是的RegisterRoutes:

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!

推荐答案

我的方法[HttpPost]属性。我可以发誓,我删除它较早,但我休息了一下,回来后,不知何故,我看到了它。取出后,现在一切工作正常。

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.

这篇关于公共行动方法没有找到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆