Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
MVC4: stackoverflow.com/questions/11990036/… –  David Tansey Nov 15 '14 at 14:19
1  
MVC5: stackoverflow.com/questions/22401403/… –  David Tansey Nov 15 '14 at 14:20
    
@DavidTansey that pointed in the right direction, thank you. –  Aaron Thomas Nov 15 '14 at 14:39

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
are you using webapi2? owin?? –  entre Nov 16 '14 at 8:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.