How do I find out whether a GET or a POST hit my ASP.NET MVC controller action?
You can separate your controller methods:
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult Operation()
{
// insert here the GET logic
return SomeView(...)
}
[AcceptVerbs(HttpVerbs.Post)]
public ViewResult Operation(SomeModel model)
{
// insert here the POST logic
return SomeView(...);
}
You can also use the ActionResults For Get and Post methods separately as below:
[HttpGet]
public ActionResult Operation()
{
return View(...)
}
[HttpPost]
public ActionResult Operation(SomeModel model)
{
return View(...);
}
You can check Request.HttpMethod
for that.
if (Request.HttpMethod == "POST") {
//the controller was hit with POST
}
else {
//etc.
}