How to convert MVC empty project to Web API?
asp.net, asp.net-mvc, asp.net-web-api, rest, visual-studio-2010
Solution
You can add a Web API controller to an MVC project. In Solution explorer, right-click the Controllers folder, select Add Controller, then pick Web API controller.
The only other thing you need is the routing - I believe the "empty" MVC 4 project already includes a Web API route by default, so you should be OK. Look for something like:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
But if you want to convert an existing MVC controller to a Web API controller, there is no automatic way to do that.
Problem
I created a an "Empty" for MVC 4. After coding some things out, I realized that an "Web API" project is better. I do not want to start over so is there a way to convert it to a Web API project instead? Below is a screenshot of what I am referring to. Any help would be greatly appreciated.