Reputation: 5281
How can an API controller be added to a project with existing MVC (non-API) controllers?
Problem:
I've created a very basic "hello world" MVC project with only one model, view, and controller. When I attempt to add the API controller (not using scaffolding), I can't get using System.Web.Http;
to show in IntelliSense. using System.Web
will show up, but the .Http
part is not available. What do I need to do or change?
Details:
I'm using VS2013 Express on a Win7 machine.
Upvotes: 2
Views: 1719
Reputation: 5281
David Tansey pointed in the right direction with his comments, but after researching there's more to this than I realized as a beginner.
First, this wasn't available in the using statement because I didn't have a reference for system.web.http in my project. Digging further, I found the reference wasn't even available! So, I had to install using NuGet Package Manager Console Powershell.
In powershell, I can't just do install-package System.Web.Http
. That package doesn't exist. But, thanks to one answer that David Tansey's comments pointed to, I noticed I could do install-package microsoft.aspnet.webapi
. Wonderful! Now System.Web.Http
is listed under References in my project, and I can write the using statement in my API controller code: using System.Web.Http;
For a beginner like me, a lot of steps to go through, and a lot of material to comprehend, to get started.
Upvotes: 2