Serhat Ozgel
Serhat Ozgel

Reputation: 23766

asp.net mvc does not run method when the request method is POST

I have a method in a controller:

public class WorkController : Controller
{
    public JsonResult GetWorks()
    {
        ...
        return Json(outDto);
    }
}

When I make a get request by Work/GetWorks, the method runs. When I do the same with a POST request, Application_BeginRequest runs, but the method does not. How can I know the reason to this?

Upvotes: 1

Views: 171

Answers (2)

tvanfosson
tvanfosson

Reputation: 532465

Can you show the code that generates the post action (i.e., BeginForm())? Is the view generating the form rendered from the same controller? My suspicion is that it may be mapped onto a different controller. You should check that the URL is what you expect.

Upvotes: 0

Falle1234
Falle1234

Reputation: 5063

Try giving your Method the following attribute:

[AcceptVerbs(HttpVerbs.Post)]

Upvotes: 2

Related Questions