5

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!

tereško
  • 58,060
  • 25
  • 98
  • 150
Barka
  • 8,764
  • 15
  • 64
  • 91
  • 1
    You don't need to change your routing rules. I've tested the same action signature here and it works fine with the default route. – Andre Calil May 20 '13 at 21:03
  • I need the rules because of other things. There is a rule at the end for urls that do not map to controllers. That rule takes hold and passes everything else to a specific controller. I updated the question with more details. – Barka May 20 '13 at 21:08
  • further details will help, indeed. One question, though: in which controller is that action implemented? – Andre Calil May 20 '13 at 21:10
  • 1
    Do you have more routing rules? – Andre Calil May 20 '13 at 21:20
  • Could you show your real route definitions? The code you have shown should work. The problem is in the `....` in your route definitions that unfortunately we cannot be guessing. – Darin Dimitrov May 20 '13 at 21:20
  • Thanks all, the problem, was that 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. – Barka May 20 '13 at 22:10

1 Answers1

9

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.

Barka
  • 8,764
  • 15
  • 64
  • 91
  • 1
    Yes how confusing, this "gotcha" will surely catch new developers sooner or later. Perhaps the best practice should be AcceptVerbs only then until Microsoft fix this un-necessary limitation, e.g. http://stackoverflow.com/questions/3843875/what-is-the-difference-between-acceptverbshttpverbs-post-and-httppost – Tony Wall Apr 02 '15 at 06:58