Site icon Dotnet Helpers

ActionVerbs Attributes in Asp.Net MVC

ActionVerbs are used when we want to control the selection of an action method based on a Http request method. For example, if we have two action method with same name then it can be respond based upon the HTTP request type(one action has  to respond to Http Get and another method have respond to Http Post). ASP.NET MVC provides attributes to tweak how the actions can be selected based on the name.

Different types of ActionVerbs

ASP.NET MVC supports different types of ActionVerbs.

In ASP .NET MVC, it can be achieve in two different ways.

Method 1: AcceptVerbs Attribute

We can apply multiple http verbs using AcceptVerbs attribute by using OR operator.

public class dotnethelpersController : Controller
{
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult EditEmpDetails(int id)
{
// retrieve the Details
}

Method 2: shortcut attributes

public class dotnethelpersController : Controller
{
[HttpGet]
public ActionResult EditEmpDetails(int id)
{
}

[HttpPost]
public ActionResult EditEmpDetails(string empCode)
{
}

Points to Remember :

Exit mobile version