Reputation: 5614
Is it possible to use Web Api in an existing project of Asp.Net MVC 4? Actually we have started the building project using Empty MVC Application template and now want to use Web Apli functionality in the project. Is it possible or do i need to add some Web Api DLL's in the project.
Upvotes: 1
Views: 967
Reputation: 1039398
Yes, it is possible. When you create a new ASp.NET MVC 4 application from the empty template you already have all the required assemblies referenced and even the API routes setup (~/App_Start/WebApiConfig.cshtml
).
So all that's left now is to right click on the Controllers
folder in your Solution Explorer and choose Add -> Controller and pick the Empty API Controller template:
public class ValuesController : ApiController
{
public string Get()
{
return "Hello from a Web API controller";
}
}
and then run the application and navigate to /api/values
which will hit the Get
action.
Upvotes: 2