Choose an ASP.NET Core web UI
ASP.NET Core is a complete UI framework. Choose which functionalities to combine that fit the app's web UI needs.
Benefits vs. costs of server and client rendered UI
There are three general approaches to building modern web UI with ASP.NET Core:
- Apps that render UI from the server.
- Apps that render UI on the client in the browser.
- Hybrid apps that take advantage of both server and client UI rendering approaches. For example, most of the web UI is rendered on the server, and client rendered components are added as needed.
There are benefits and drawbacks to consider when rendering UI on the server or on the client.
Server rendered UI
A web UI app that renders on the server dynamically generates the page's HTML and CSS on the server in response to a browser request. The page arrives at the client ready to display.
- The client requirements are minimal because the server does the work of logic and page generation:
- Great for low-end devices and low-bandwidth connections.
- Allows for a broad range of browser versions at the client.
- Quick initial page load times.
- Flexibility of access to protected server resources:
- Database access.
- Access to secrets, such as values for API calls to Azure storage.
- Static site analysis advantages, such as search engine optimization.
Examples of common server rendered web UI app scenarios:
- Dynamic sites such as those that provide personalized pages, data, and forms.
- Display read-only data such as transaction lists.
- Display static blog pages.
- A public-facing content management system.
- The cost of compute and memory use are concentrated on the server, rather than each client.
- User interactions require a round trip to the server to generate UI updates.
Client rendered UI
A client rendered app dynamically renders web UI on the client, directly updating the browser DOM as necessary.
- Allows for rich interactivity that is nearly instant, without requiring a round trip to the server. UI event handling and logic run locally on the user's device with minimal latency.
- Supports incremental updates, saving partially completed forms or documents without the user having to select a button to submit a form.
- Can be designed to run in a disconnected mode. Updates to the client-side model are eventually synchronized back to the server once a connection is re-established.
- Reduced server load and cost, the work is offloaded to the client. Many client rendered apps can also be hosted as static websites.
- Takes advantage of the capabilities of the user’s device.
Examples of client rendered web UI:
- An interactive dashboard.
- An app featuring drag-and-drop functionality
- A responsive and collaborative social app.
- Code for the logic has to be downloaded and executed on the client, adding to the initial load time.
- Client requirements may exclude user's who have low-end devices, older browser versions, or low-bandwidth connections.
Choose a server rendered ASP.NET Core UI solution
The following section explains the ASP.NET Core web UI server rendered models available and provides links to get started. ASP.NET Core Razor Pages and ASP.NET Core MVC are server-based frameworks for building web apps with .NET.
ASP.NET Core Razor Pages
Razor Pages is a page-based model. UI and business logic concerns are kept separate, but within the page. Razor Pages is the recommended way to create new page-based or form-based apps for developers new to ASP.NET Core. Razor Pages provides an easier starting point than ASP.NET Core MVC.
Razor Pages benefits, in addition to the server rendering benefits:
- Quickly build and update UI. Code for the page is kept with the page, while keeping UI and business logic concerns separate.
- Testable and scales to large apps.
- Keep your ASP.NET Core pages organized in a simpler way than ASP.NET MVC:
- View specific logic and view models can be kept together in their own namespace and directory.
- Groups of related pages can be kept in their own namespace and directory.
To get started with your first ASP.NET Core Razor Pages app, see Tutorial: Get started with Razor Pages in ASP.NET Core. For a complete overview of ASP.NET Core Razor Pages, its architecture and benefits, see: Introduction to Razor Pages in ASP.NET Core.
ASP.NET Core MVC
ASP.NET MVC renders UI on the server and uses a Model-View-Controller (MVC) architectural pattern. The MVC pattern separates an app into three main groups of components: Models, Views, and Controllers. User requests are routed to a controller. The controller is responsible for working with the model to perform user actions or retrieve results of queries. The controller chooses the view to display to the user, and provides it with any model data it requires. Support for Razor Pages is built on ASP.NET Core MVC.
MVC benefits, in addition to the server rendering benefits:
- Based on a scalable and mature model for building large web apps.
- Clear separation of concerns for maximum flexibility.
- The Model-View-Controller separation of responsibilities ensures that the business model can evolve without being tightly coupled to low-level implementation details.
Choose a client rendered ASP.NET Core solution
The following section briefly explains the ASP.NET Core web UI client rendered models available and provides links to get started.
Blazor apps are composed of Razor components: segments of reusable, web UI implemented using C#, HTML, and CSS. Both client and server code are written in C#, allowing shared code and libraries. Razor components can be rendered or prerendered from views and pages.
Benefits of Razor components:
- Accelerate app development.
- Reduce build pipeline complexity.
- Simplify maintenance.
- Leverage the existing .NET ecosystem of .NET libraries.
- Let developers understand and work on both client-side and server-side code.
- Create reusable, sharable UI components.
- Quickly get productive with Blazor reusable UI components from top component vendors.
- Work with all modern web browsers, including mobile browsers. Blazor uses open web standards without plug-ins or code transpilation.
Host Razor components either using Blazor Server or Blazor WebAssembly to take advantage of server or client rendering.
- Large community and mature ecosystem.
- Build client-side logic for ASP.NET Core apps using popular JS frameworks, like Angular and React.
- More coding languages, frameworks, and tools required.
- Difficult to share code so some logic may be duplicated.
To get started, see:
Choose a hybrid solution: ASP.NET Core MVC or Razor Pages plus Blazor
MVC, Razor Pages, and Blazor are part of the ASP.NET Core framework and are designed to be used together. Razor components can be integrated into Razor Pages and MVC apps in a hosted Blazor WebAssembly or Blazor Server solution. When a view or page is rendered, components can be prerendered at the same time.
Benefits for MVC or Razor Pages plus Blazor, in addition to MVC or Razor Pages benefits:
- Prerendering executes Razor components on the server and renders them into a view or page, which improves the perceived load time of the app.
- Add interactivity to existing views or pages with the Component Tag Helper.
To get started with ASP.NET Core MVC or Razor Pages plus Blazor, see Prerender and integrate ASP.NET Core Razor components.
For more information, see:
Submit and view feedback for