I have a controller action method that works when it looks like this:
public ActionResult testMethod(int id) {
But when I point out that this should be the Publish method, I get the "404 not found" error:
[HttpPost] public ActionResult testMethod(int id) {
I have other controller action methods in one controller - both POST and GET, and they work fine. But is it not? What's happening? (I'm sure I'm missing something obvious here ...)
Update: Ajax call requests the controller method: var id = 1;
$.ajax({ url: '/indices/testMethod/', data: id, type: 'POST', success: function (data) {
I also tried to test the method using Postman, making sure the POST request was sent.
Update 2: I tried changing the parameter to id and trying to make sure that all areas of the methods and URLs were capitalized to match, but without any effect.
In Fiddler, I see that the GET request is actually being executed, although I specify the POST request in the ajax call, so now I need to find out why the request ends up sending as GET, not POST.
I also tried to include an attribute route description like
[HttpPost] [Route("indices/TestMethod/{id:int}")] public ActionResult TestMethod(int id)
And then tried an ajax call with a different url:
$.ajax({ url: '/indices/TestMethod/1', data: id, type: 'POST', success: function (data) { var tr = 123; var yr = data;
When I turn on the attribute and parameter in the URL, I see in Fiddler that the POST request is first executed, which receives a 301 status error, but then the GET request, which receives the 404 error, is also executed.
Update 3: After further research, I narrowed down the problem definition enough to make sense to open a new question, which can be found here: ASP MVC jQuery $ .ajax POST request does not call the controller method, but works in the "fresh" MVC project
The problem seems to be caused by the content security policy settings that were active for this project.