How do I find out whether a GET or a POST hit my ASP.NET MVC controller action?
views:
106answers:
2
+3
A:
You can check Request.HttpMethod
for that.
if (Request.HttpMethod == "POST") {
//the controller was hit with POST
}
else {
//etc.
}
çağdaş
2009-07-23 03:49:29
+5
A:
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(...);
}
Remus Rusanu
2009-07-23 03:55:36
Great idea. Thank you
Alex
2009-07-23 04:03:53