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

October 23, 2012 comment

ASP.NET MVC: HttpPost action filter


In ASP.NET MVC controller, HttpPost action method selector attribute let us restrict action method so that specified action method is only accessible via HTTP POST verb or request. HttpPost is inherited from ActionMethodSelectorAttribute which is used to validate action method selection based on controller context.

Attribute Usage: Only method

Sample Code:

public ActionResult About()
    return Json(Model);

Generally we should mark action method with HttpPost whenever we are returning Json result from action method in other word whenever action method is consumed by only AJAX request at that time we should mark it with HttpPost attribute. However this is not the only scenario. If we try to access action method with other than POST verb then it will throw HTTP 404 not found error.

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