Public action method was not found on controller
25,671
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.
Comments
-
Barka over 3 years
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!
-
Tony Wall about 9 yearsYes 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. stackoverflow.com/questions/3843875/…