We can decorate the MVC action with the HttpGet or HttpPost attribute to restrict the type of HTTP calls.
For example you can see in the below code snippet the Home action can only be invoked by HttpGet. If we try to make HTTP POST on Home, it will throw an error.
//GET
[HttpGet]
public ActionResult Home()
{
return View();
}
//POST
[HttpPost]
public ActionResult Home(Int Id)
{
return View(Id);
}
For example you can see in the below code snippet the Home action can only be invoked by HttpGet. If we try to make HTTP POST on Home, it will throw an error.
//GET
[HttpGet]
public ActionResult Home()
{
return View();
}
//POST
[HttpPost]
public ActionResult Home(Int Id)
{
return View(Id);
}
No comments:
Post a Comment