how to create a web application using the ASP.NET Web API 2 project template and do some data operations like reading the data from the database and calling the Web API Controller method in the MVC Controller and call the adjacent view? any resources for that? I found one but it doesn;t go into much detail
http://www.c-sharpcorner.com/UploadFile/4b0136/integrating-Asp-Net-web-api-with-mvc-basic-infrastructure-by/
The below example provides a detailed explanation on how to call WebApi from a C# app, you can follow same for the asp.net mvc application also
http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client
Related
I have an existing asp.net MVC 5 web application. I do not want to crate a separate project for asp.net webapi OData and I want re-use www domain of the web app for OData app. I'd like to add some ODataControllers to that MVC web application to be consumed in some cshttml view pages with flexible, robust queries. Is it possible to do that? If so, how is about the routing configs must be updated for web app routes and OData routes? Thank you.
I am very new to MVC, My requirement is to develop application using Web Api 2 ,Asp.net identity ,Entity framework code first method. Can i put my web api and mvc in same project? can i generate api controller and controller from single model class using identity? I did a lot of search for this but i din't get perfect solution.
Thanks in advance
When I create a new ASP.NET MVC 4.0 project e.g. Single Page App or Mobile etc... they all have Controller classes inheriting from ApiController.
I do not need to expose a web service to someone else. I just want to run a public website with a private webapplication if logged in. I do not want ApiController but I want a Single Page App.
Why have they done it that way?
WebApi does not necessarily imply that you are creating a web service for someone else. Instead, when you are developing a single page app, you would use the WebApi controllers to deal with getting/posting data via ajax.
There is nothing stopping you from using regular controllers, but the WebApi is well suited for SPA. See any of the online tutorials where this technique is used.
It sounds like you want to create an Mvc4 Web Application using the Internet Application project template. This template uses forms authentication and creates controllers that inherit from System.Web.Mvc.Controller. If you are using Visual Studio 2012 then this template is installed (along with a handful of others including the Api Web template).
Right click on your controllers folder -> Add -> Controller and then choose an MVC controller from the template drop down. You don't have to use an API Controller.
If you think of what a SPA is, it's essentially an HTML page that uses JavaScript to get data from a WebAPI or some other web service. Like Bort said, web API calls are very well suited for SPA.
Personally, for a single page app, before they added the SPA template in Update 1 I'd just create a static .html page and make RESTful calls into my WebAPI controllers.
What's the advantage of ASP.NET Web API to ASP.NET MVC Controller?
As far as I know, IIS + WebDAV conflicts with ASP.NET Web API while using "PUT" verb[1].
We can use ASP.NET MVC Controller & JsonResult, etc. to communicate with clients, which use HTTP GET+POST and no more verb to get better compatibility, so what's the advantage of ASP.NET Web API to ASP.NET MVC?
And, ASP.NET Web API should only use the desigend teens HTTP verbs. If I'd like to develop a Web API to let a robot JUMP, but JUMP is not a standard HTTP verb. So how to design the url? http://localhost/api/robot/jump ? But it is not RESTful(RESTful urls should not contain verb).
reference:
[1] http://forums.iis.net/t/1163441.aspx
If you are asking about the difference between Asp.Net application .cs files and controllers in MVC.
We can navigate to required method in MVC depending upon requirement but this is not possible in Asp.Net web.
Always, firing the page load event will not happen.
We can return partial results/Json results/Javascript results and so on.
Unlike Asp.Net life cycle, MVC has its own page life cycle.
Regards,
Pavan.G
I found that Asp.net Mvc controller can serve both Asp.net Mvc View and Silverlight application via DynamicActionResult(It can be Simple Action Result or Json Action Result depend on request type). So, I have 3 options for creating middle-tier for Silverlight application.
Pure WCF Service Every request to WCF must be declare in interface. So, it's strongly-typed connection.
Asp.net MVC Controller It can serve both Asp.net MVC View and Silverlight application at the same time.
Using both of them I found that it's possible to doing this by using the answer in the following link. I think, It doesn't good idea for creating both of them.
WCF Service with Asp.net MVC application
Which's the best performance between WCF Service and Asp.net MVC Controller?
Thanks,
Do you have the kind of service that would benefit from caching? If so, my testing says that MVC with Output Caching turned on is very much faster than WCF.