Are M and V from MVC required even in ASP.NET Web API?

I have a web API application that uses a single controller that returns data read from a file.

So, all I use is part of the C (Controller) MVC. I have no views, and I also do not use models - I store and retrieve data in / from the App_Data folder.

I know this is a fairly simple solution, but it seems that all I need is C, not MVC. Did I miss something?

+4
source share
5 answers

Model-View-Controller is a design template to help structure GUI applications. ASP.NET MVC is an environment that helps you build a web application according to this design pattern.

The web API has nothing to do with the MVC design pattern. It was developed separately, temporarily distributed under the same umbrella name, and now with its own structure: http://www.asp.net/web-api

The fact that some project templates still create the Model and Views catalogs in your project means that you are using an outdated project template or one that assumes you want MVC and web API in the same project .

+7
source

CodeCaster "" . , , , , , -API , ASP.NET MVC.

Visual Studio 2013 -. , . Web Api. . -Api (, , , ), - MVC " ​​" , , , "" ( ): :

enter image description here

Ok , API MVC. , , .

, "" -API, , -API, :

, -API.

enter image description here

+3

, , . , , . . . MVC, .

+2

, /, , . , Model View , , . , MS ASP.NET MVC , , MVC - MS. (, EF-, Razor views) .

, ( POST), JSON ( GET). GET/POST? GET POST. , JSON , .

+1

If we do not consider the data returned by the controller action as a representation, a representation of your data, and not an HTML representation, the design pattern does not indicate the type of representation. In my opinion, this is still MVC, the model still exists, and you would usually create the model of your data that you want to return, part of the view is just another model or a representation of your main model classes.

+1
source

Source: https://habr.com/ru/post/1622449/


All Articles