This ActionVerbs in MVC is used to control the selection of an action method based on the Http request method like POST, GET, DELETE, etc. Sometimes we want the same Action Method to perform on more than one Http Request then at that time we can use Action Verbs attribute which would be shown like below
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)] public ActionResult Home()
{
return View();
}
In Above Home() method will support both get and post requests in MVC. The following example to use Action Verbs in controller action methods in MVC
using System; using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Tutorial4.Controllers
{
public class HomeController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult GetPerson()
{
Person p = newPerson ();
return View("Person",p);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Insert(Person p)
{
return View("Person");
}
[AcceptVerbs(HttpVerbs.Put)]
public ActionResult Update(Person p)
{
return View("Person");
}
[AcceptVerbs(HttpVerbs.Delete)]
public ActionResult Delete(string ID)
{
return View("Person");
}
}
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
This ActionVerbs in MVC is used to control the selection of an action method based on the Http request method like POST, GET, DELETE, etc. Sometimes we want the same Action Method to perform on more than one Http Request then at that time we can use Action Verbs attribute which would be shown like below
In Above Home() method will support both get and post requests in MVC. The following example to use Action Verbs in controller action methods in MVC