2

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.

3

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

are you using webapi2? owin??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.