Answer the question
In order to leave comments, you need to log in
How is ASP.NET MVC development different from ASP.NET API development?
How is ASP.NET MVC development different from ASP.NET API development?
it is the same accepting "methods" on views, with accepting variables? which give back the application/json/xml page?
Answer the question
In order to leave comments, you need to log in
First of all, you need to look at inheritance, how they work:
If you pay attention, webapi and asp.mvc (hereinafter simply mvc) controllers are inherited from different Http.ApiController and Mvc.Controller classes.
You need to understand that webapi is designed to implement REST services covering all types of http requests (GET, PUT, POST, DELETE, etc.) and in response to requests to webapi you get json with an explicit indication of the response status .
In MVC, you can implement the same thing as in webapi, BUT! I personally think that these things need to be clearly distinguished, since in cases with MVC, you must understand that the result of the request in most cases is a generated view, that is, the result of an http request in most cases is html or something similar. Yes, structured json can also be returned to mvc (for example, if you make a table with pagination or dynamic data loading, in this case your Index method returns a view on which you write ajax requests to the GetPageForTable method of the same controller, but there is also a variation, you are free to decide in the GetPageForTable method whether to return only the data or an already generated view).
As a result: webapi is a rest service with all types of http requests, in which the response (by default) comes in a structured json and with an explicit state status (200, 404, etc...) . Well suited for projects where the client can be not only the web, but also a mobile application or something else.
MVC - works like webapi but the result can be generated html markup. In such cases, it is already impossible to support many platforms from the client side, imagine what a mobile application should do with html markup...
return of the result.
In the first case you get html by default, in the second json or xml.
In MVC 6 WEBAPI is already built in. So there are no fundamental differences.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question