I\'m getting an intermittent exception saying that asp.net mvc can’t find the action method. Here’s the exception:
A public action method \'Fill\' cou
We just had the same issue on our application and I was able to trace it to a javascript/jquery issue. We have links in our application defined using Html.ActionLink() that are later overridden into POSTs by jquery.
First we had defined the link:
Html.ActionLink("Click Me", "SomeAction", new { id = Model.Id})
Later we override the default action with our SomePostEventHandler function:
$(document).ready(function() {
$('#MyLink').click(SomePostEventHandler);
}
This was hitting our MVC action that had a HttpPost filter:
[HttpPost]
public ActionResult SomeAction(int id)
{
//Stuff
}
What we found is that most of the time this worked great. However, on some slow page loads (or really fast users), the user was clicking the link before the jquery $(document).ready() event was firing, meaning that they were trying to GET /Controller/SomeAction/XX instead of posting.
We don't want the user to GET that url, so removing the filter is not an option for us. Instead we just wired the onclick event of the action link directly (we had to change SomePostEventHandler() slightly for this to work):
string clickEvent = "return SomePostEventHandler(this);";
Html.ActionLink("Click Me", "SomeAction", new { id = Model.Id}, new { onclick = clickEvent })
So, moral of the story, for us at least, is that if you are seeing these errors, track down the URL that you THINK you are POSTing to and make sure you are.
Remove the [HttpGet]
attributes and it will work :)
My root cause was similar to the one mentioned in the comment.
I was ajaxSubmitting
a form upon the click of a button. One of the form fields was of type Date
. However, because of the difference in the date formats between the client and server machine it did not execute the POST method in the controller. The server sent back a 302
response and then sent a GET
request for the same method again.
However, the action in the controller was decorated with the HttpPost
attribute and hence it could not find the method and sent back a 404
response.
I just fixed the code such that the mismatch in the Date formats would not cause an error and the problem was fixed.
Shouldn't it be
routes.MapRoute(
"SchoonForm",
"Form/Fill/{subscriberId}",
new { controller = "Chris", action = "Fill" },
Also, what do your filters do? Can't they hide action, like ActionMethodSelectorAttribute?
I have the similar issue with qq File Upload
When the post action is /Document/Save
I get the exception A public action method 'Save' was not found on controller 'Project.Controllers.DocumentController'.
But if the post action is /Document/Save/
, the post is correct and works!
God save the / ?
We had a similar issue, but found that it was happening because a user was posting to a controller after his login had timed out. The system then redirected to the login screen. After logging in it redirected back to the URL the user was trying to post to, but this time it was doing a GET request instead and therefore not finding the action which was marked with an [HttpPost] attribute.