What is the difference between the ASP.NET web application attributes "System.Web.Http.HttpPostAttribute" and "System.Web.Mvc.HttpPostAttribute"?
Posted: (EET/GMT+2)
When working with ASP.NET MVC applications in Visual Studio, you might run into the following C# compiler error in your controllers:
Error CS0104: 'HttpPost' is an ambiguous reference between 'System.Web.Http.HttpPostAttribute' and 'System.Web.Mvc.HttpPostAttribute'
That is, both namespaces define an attribute named "HttpPost". What is the difference between these two?
Both attributes refer to HTTP protocol verbs, but the attribute defined in the System.Web.Http namespace is for Web API controllers only. The other, defined in the System.Web.Mvc namespace is for regular (interactive) MVC controllers.
In some cases, you might need to have "using" statements to both namespaces in your controllers, leading to the above compiler error. In these situations, just use the fully-qualified name of the attribute like this:
[System.Web.Mvc.HttpPost]
Hope this helps!