i search google but not found a details article on How to work with Web API and MVC together in same project. basically people host web api in separate project but i like to know how could i have web api controller in same mvc project. i want to know how
mvc controller can communicate with web api controller. looking for details discussion with sample code & details instruction. thanks
A quick Google search gave the following links:
Hope this helps.
below article gives you step by step implementation of ASP.NET Web API in MVC application
How to work with Web API and MVC together in same project.
A WebAPI class by default can be placed at any folder in the MVC project. Sometimes I create an API sub folder under Controller folder and keep all my WebAPI controllers.
i want to know how mvc controller can communicate with web api controller
WebAPI is typically called from an Ajax request, i.e, from the browser (though not necessarily). If MVC and WebAPI reside in the project, then there is no point calling a WebAPI from a MVC controller
suppose i need to call web api action from mvc action method then what will be the code……guide me. thanks
Thanks for your post.
WebApi is an alternative Service oriented application from Microsoft just like WCF. But WCF uses SOAP protocol and WebAPI uses HTTP protocol for communication.
So if you are using WCF to provide service for your MVC application you would host that wcf service seperately and consume its service by MVC application, EXACTLY same way you have to host your WebAPI project seperately and provide service to your Web application
for some reasons if you want them (MVC and WebAPI) to use in the same project, follow this rules from this article.
More information:Add Web API to an existing MVC 5 Web Application
Hope this can be helpful.
Go through the links I posted. It shows you exactly how to do that.
suppose i need to call web api action from mvc action method then what will be the code
Typically you need to call a Web API that is remotely hosted from MVC. In that scenario please take a look at this post