@Blog.Author(Nandip Makwana) .LearningExperience(ASP.NET, ASP.NET MVC, IIS, jQuery & Technology Surrounding it...)

November 8, 2012 comment

ASP.NET MVC: AcceptVerbs action filter

ASP.NET MVC: AcceptVerbs

So far we have seen various action filter in ASP.NET MVC which allow us to restrict action method usage based on HTTP verb or method. But with the usage of HttpGet, HttpPost, HttpPut or other such action filter, we are limited to only respective HTTP verb. But sometime we require that action method should be accessible by more than one HTTP verb but not all. This is the case where AcceptVerbs comes in picture.

In this case, we can use AcceptVerbs action filter. Here we can specify list of HTTP verbs and action method would be accessible by only those verbs.

Attribute Usage: Only method

Sample Code:

[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult About()
{
    return View();
}

In above example, action method will be accessible by only HTTP GET & POST verbs. Following is the full list of possible value for AcceptVerbs

  • HttpVerbs.Get
  • HttpVerbs.Post
  • HttpVerbs.Put
  • HttpVerbs.Delete
  • HttpVerbs.Head
  • HttpVerbs.Patch
  • HttpVerbs.Options

We can use any combination from above list with AcceptVerbs filter.

Check out ASP.NET MVC: Action filter series post to read about other available action filters.

You can follow me on twitter for latest link and update on ASP.NET & MVC.

comments powered by Disqus

Featured Content

Resources & Tools

About Nandip Makwana

Nandip Makwana is passionate about digital world and web. He completed his Masters in Computer Application in June 2011. Currently he is working as a Software Engineer. He has shown great promise and command over ASP.NET and technologies surrounding it during his academic years and professorial life...continue reading