tl;dr: You should never have references to
System.Web.Mvc.* in an
One thing that took me longer than I’d care to admit to realize when working with Web API and
ApiController is that Web API has its own namespace to do a lot of the stuff I was used to
So, for example, there’s a
System.Web.Mvc.HttpPostAttribute class that you’d use to decorate a controller action to tell it to accept HTTP POST requests.
If you’re trying to do that on an
ApiController action, you’ll want to use
The code ends up looking the same, mostly, though, because instead of including
using System.Web.Mvc; at the top, you’ll have
using System.Web.Http, and you’ll end up writing the attribute as just
This doesn’t just apply to those attributes, either. Web API uses that
System.Web.Http stuff for action filters, configuration, and plenty of other stuff. You should never need to include
System.Web.Mvc.* for anything in an API controller.