Answer the question
In order to leave comments, you need to log in
How to build Single Page Application on ASP.NET?
I'm trying to find information on the Internet how to build single page applications in ASP.NET. Specifically, which technology to use: ASP.NET MVC or ASP.NET Web API?
As far as I understand, in the first case there are two options:
Answer the question
In order to leave comments, you need to log in
Basically, you've described two ways of building SPA rendering: server rendering and client rendering.
The first approach has a minus in a large amount of data transferred, but a plus in simple rendering without load on the client (we simply replace part of the DOM tree with the one that came from the server). The second approach has the advantage of less data transfer, but the disadvantage of more manipulation of the DOM tree, which can affect the responsiveness of the page. But, for example, React and Angular currently work with the so-called "shadow" or "virtual" DOM tree, when the tree is built in memory and simply replaced, so the second minus, in principle, is no longer a minus if you use these tools .
There is also an isomorphic approach to building a SPA: at the first request, the page is rendered on the server and given to the client, after which scripts are loaded in the background and then everything is rendered on the client, the server returns only JSON.
There are ready-made project templates for ASP.NET Core. Just a couple of commands are enough to create, for example, a project based on Angular:
dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
cd <project_folder>
dotnet new angular
In general, using ASP.NET MVC for SPA applications is a so-so idea. The most ideal bundle (in an ASP.NET environment) is ASP.NET Core Web API + a separate Angular / React project that can be built into the wwwroot Web API folder of the project for production. Specifically, such an implementation option was discussed here.. In short: create a Web API project (where you keep requests that will return or write the necessary data) and create an Angular / React / Any Other Framework project that is fully responsible for the web interface; set up a proxy for requests (to pull API methods from a separate project during development); teach your builder to build the project in the wwwroot folder; profit :). As a result, we have two projects that, during development, communicate from two different ports, and in production, one project that opens the index.html page with all the logic from wwwroot.
We have this:
1) we get an html page
2) it loads JS scripts
3) they access ashx - which return json
4) from json we generate HTML code on the client.
As an option, generate HTML code on the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question