I'd like to have a single action respond to both Gets as well as Posts. I tried the following
[HttpGet] [HttpPost] public ActionResult SignIn()
That didn't seem to work. Any suggestions ?
While ASP.NET MVC will allow you to have two actions with the same name, . NET won't allow you to have two methods with the same signature - i.e. the same name and parameters. You will need to name the methods differently use the ActionName attribute to tell ASP.NET MVC that they're actually the same action.
Both GET and POST method is used to transfer data from client to server in HTTP protocol but the Main difference between the POST and GET method is that GET carries request parameter appended in URL string while POST carries request parameter in message body which makes it more secure way of transferring data from ...
HttpGet and HttpPost are both the methods of posting client data or form data to the server. HTTP is a HyperText Transfer Protocol that is designed to send and receive the data between client and server using web pages.
Yes, completely possible. And, it can be multiple views, or even a FileResult or other result type.
This is possible using the AcceptVerbs attribute. Its a bit more verbose but more flexible.
[AcceptVerbs(HttpVerbs.Get|HttpVerbs.Post)] public ActionResult SignIn() { }
More on msdn.
Actions respond to both GETs and POSTs by default, so you don't have to specify anything:
public ActionResult SignIn() { //how'd we get here? string method = HttpContext.Request.HttpMethod; return View(); }
Depending on your need you could still perform different logic depending on the HttpMethod by operating on the HttpContext.Request.HttpMethod value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With