Doubts about routes JS angular x ASP.NET MVC

2

I would like to remedy some doubts about Angular JS vs. ASP.NET MVC.

I created an empty ASP.NET MVC application that will work with WEB API, configured all my routes with AngularJS, created an html page and its controllers, all with angularJS, my question is this, these routes between pages are sent any requests for the server? if the page has something to load as a log list via $ http.get method the request is made via ajax, ie the page is not loaded?

I was wondering why, in ASP.NET MVC all controllers calls are called a request on the server, since the razor has to build the views and then present them to the right user?

Could anyone understanding the issue describe more about the benefits of using angularJS and ASP.NET MVC routing?

    
asked by anonymous 23.11.2017 / 12:26

1 answer

4

First of all, a brief explanation of the two technologies:

About AngularJS

It is a framework for writing applications client-side . Where you develop in JavaScript and everything developed there will run on the client side ( browser ).

Most of the time, data is only sent / received and so if you use some other technology server-side (like a C # with ASP.NET, a Ruby application, or any other).

For example, requests are made to the server and the server responds with data only (whether in JSON, XML, plaintext or any other available type). This data should be treated on the client side.

Of course nothing prevents you from getting the server to return an HTML or something similar, keep in mind that what I say is how you normally work, there are no rules that really restrict this.

About ASP.NET MVC

It is a web framework to work on the server side, receive, process and respond to requests.

In most cases the requests are made to the server and the server responds with a page already mounted, that is, all the processing of the data is done on the server side and sent to the client.

Of course, there may be client-side data handling using JavaScript, but that's another story.

Now, let's ask your questions:

  

Does this routing between pages send any requests to the server?

No. The idea is precisely that (almost) no contact with the server is made by exchanging the exchange (the state) of the application.

  

If the page has something to load as a log list via method $http.get the request is made via Ajax , ie the page is not loaded?

Exactly. This is the purpose of asynchronous requests.

  

I wondered, because in ASP.NET MVC all controllers calls are called on the server because razor has to construct the views and then submit to the right user?

Obviously. ASP.NET is a web framework for the server .

Basically, think of the following flow.

  • The browser requests a page

  • The server receives the request and sends it to the ASP.NET MVC application

  • The application processes the request, delegates the execution to a controller which, in turn, delivers the execution to the Razor all the view code and deliver a pretty HTML to the browser interpret

  • The browser receives the response and shows the HTML for the user

  • This is repeated as many times as needed

  

Could anyone understanding the issue describe more about the benefits of using angularJS and ASP.NET MVC routing?

I do not understand the subject, but I can tell you that there is no advantage to using over the other. Each serves a specific purpose and they are completely different.

If the application is a SPA that only needs to query data on the server (at least most of the time), it will probably be necessary to use the route system of AngularJS. If it is a normal application, where most requests to the server will return a full page, it is very likely that it is preferable to use default routing.

Suggested Read:

23.11.2017 / 12:39