You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/mvc/overview.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Overview of ASP.NET Core MVC
3
3
author: ardalis
4
4
description: Learn how ASP.NET Core MVC is a rich framework for building web apps and APIs using the Model-View-Controller design pattern.
5
5
ms.author: tdykstra
6
-
ms.date: 02/12/2020
6
+
ms.date: 04/29/2026
7
7
uid: mvc/overview
8
8
---
9
9
# Overview of ASP.NET Core MVC
@@ -14,7 +14,7 @@ ASP.NET Core MVC is a rich framework for building web apps and APIs using the Mo
14
14
15
15
## MVC pattern
16
16
17
-
The Model-View-Controller (MVC) architectural pattern separates an application into three main groups of components: Models, Views, and Controllers. This pattern helps to achieve [separation of concerns](/dotnet/standard/modern-web-apps-azure-architecture/architectural-principles#separation-of-concerns). Using this pattern, user requests are routed to a Controller which is responsible for working with the Model to perform user actions and/or retrieve results of queries. The Controller chooses the View to display to the user, and provides it with any Model data it requires.
17
+
The Model-View-Controller (MVC) architectural pattern separates an application into three main groups of components: Models, Views, and Controllers. This pattern helps to achieve [separation of concerns](/dotnet/architecture/modern-web-apps-azure/architectural-principles#separation-of-concerns). Using this pattern, user requests are routed to a Controller, which is responsible for working with the Model to perform user actions and/or retrieve results of queries. The Controller chooses the View to display to the user, and provides it with any Model data it requires.
18
18
19
19
The following diagram shows the three main components and which ones reference the others:
20
20
@@ -23,7 +23,7 @@ The following diagram shows the three main components and which ones reference t
23
23
This delineation of responsibilities helps you scale the application in terms of complexity because it's easier to code, debug, and test something (model, view, or controller) that has a single job. It's more difficult to update, test, and debug code that has dependencies spread across two or more of these three areas. For example, user interface logic tends to change more frequently than business logic. If presentation code and business logic are combined in a single object, an object containing business logic must be modified every time the user interface is changed. This often introduces errors and requires the retesting of business logic after every minimal user interface change.
24
24
25
25
> [!NOTE]
26
-
> Both the view and the controller depend on the model. However, the model depends on neither the view nor the controller. This is one of the key benefits of the separation. This separation allows the model to be built and tested independent of the visual presentation.
26
+
> Both the view and the controller depend on the model. However, the model doesn't depend on the view or the controller. This is one of the key benefits of the separation. This separation allows the model to be built and tested independent of the visual presentation.
27
27
28
28
### Model Responsibilities
29
29
@@ -39,7 +39,7 @@ Controllers are the components that handle user interaction, work with the model
39
39
40
40
> [!NOTE]
41
41
> Controllers shouldn't be overly complicated by too many responsibilities. To keep controller logic from becoming overly complex, push business logic out of the controller and into the domain model.
42
-
42
+
>
43
43
>[!TIP]
44
44
> If you find that your controller actions frequently perform the same kinds of actions, move these common actions into [filters](#filters).
The framework handles validating request data both on the client and on the server. Validation logic specified on model types is added to the rendered views as unobtrusive annotations and is enforced in the browser with [jQuery Validation](https://jqueryvalidation.org/).
119
+
The framework handles validating request data both on the client and on the server. Validation logic specified on model types is added to the rendered views as unobtrusive annotations and is enforced in the browser with [jQuery Validation](https://github.com/jquery-validation/jquery-validation).
120
120
121
121
## Dependency injection
122
122
123
-
ASP.NET Core has built-in support for [dependency injection (DI)](../fundamentals/dependency-injection.md). In ASP.NET Core MVC, [controllers](controllers/dependency-injection.md) can request needed services through their constructors, allowing them to follow the [Explicit Dependencies Principle](/dotnet/standard/modern-web-apps-azure-architecture/architectural-principles#explicit-dependencies).
123
+
ASP.NET Core has built-in support for [dependency injection (DI)](../fundamentals/dependency-injection.md). In ASP.NET Core MVC, [controllers](controllers/dependency-injection.md) can request needed services through their constructors, allowing them to follow the [Explicit Dependencies Principle](/dotnet/architecture/modern-web-apps-azure/architectural-principles#explicit-dependencies).
124
124
125
125
Your app can also use [dependency injection in view files](views/dependency-injection.md), using the `@inject` directive:
126
126
@@ -149,23 +149,23 @@ public class AccountController : Controller
Copy file name to clipboardExpand all lines: aspnetcore/mvc/views/layout.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Layout in ASP.NET Core
3
3
author: tdykstra
4
4
description: Learn how to use common layouts, share directives, and run common code before rendering views in an ASP.NET Core app.
5
5
ms.author: tdykstra
6
-
ms.date: 07/30/2019
6
+
ms.date: 04/29/2026
7
7
uid: mvc/views/layout
8
8
---
9
9
# Layout in ASP.NET Core
@@ -16,7 +16,7 @@ Pages and views frequently share visual and programmatic elements. This article
16
16
* Share directives.
17
17
* Run common code before rendering pages or views.
18
18
19
-
This document discusses layouts for the two different approaches to ASP.NET Core MVC: Razor Pages and controllers with views. For this topic, the differences are minimal:
19
+
This document discusses layouts for the two different approaches to ASP.NET Core MVC: Razor Pages and controllers with views. For this article, the differences are minimal:
20
20
21
21
* Razor Pages are in the *Pages* folder.
22
22
* Controllers with views uses a *Views* folder for views.
@@ -27,7 +27,7 @@ Most web apps have a common layout that provides the user with a consistent expe
Common HTML structures such as scripts and stylesheets are also frequently used by many pages within an app. All of these shared elements may be defined in a *layout* file, which can then be referenced by any view used within the app. Layouts reduce duplicate code in views.
30
+
Common HTML structures such as scripts and stylesheets are also frequently used by many pages within an app. All of these shared elements might be defined in a *layout* file, which any view used within the app can then reference. Layouts reduce duplicate code in views.
31
31
32
32
By convention, the default layout for an ASP.NET Core app is named `_Layout.cshtml`. The layout files for new ASP.NET Core projects created with the templates are:
33
33
@@ -87,13 +87,13 @@ The following markup uses the [Partial Tag Helper](xref:mvc/views/tag-helpers/bu
87
87
}
88
88
```
89
89
90
-
The preceding markup was generated by [scaffolding Identity](xref:security/authentication/scaffold-identity).
90
+
[Scaffolding Identity](xref:security/authentication/scaffold-identity) generated the preceding markup.
91
91
92
-
Sections defined in a page or view are available only in its immediate layout page. They cannot be referenced from partials, view components, or other parts of the view system.
92
+
Sections defined in a page or view are available only in its immediate layout page. They can't be referenced from partials, view components, or other parts of the view system.
93
93
94
94
### Ignoring sections
95
95
96
-
By default, the body and all sections in a content page must all be rendered by the layout page. The Razor view engine enforces this by tracking whether the body and each section have been rendered.
96
+
By default, the layout page must render the body and all sections in a content page. The Razor view engine enforces this by tracking whether the body and each section have been rendered.
97
97
98
98
To instruct the view engine to ignore the body or sections, call the `IgnoreBody` and `IgnoreSection` methods.
99
99
@@ -103,7 +103,7 @@ The body and every section in a Razor page must be either rendered or ignored.
103
103
104
104
## Importing Shared Directives
105
105
106
-
Views and pages can use Razor directives to import namespaces and use [dependency injection](dependency-injection.md). Directives shared by many views may be specified in a common `_ViewImports.cshtml` file. The `_ViewImports` file supports the following directives:
106
+
Views and pages can use Razor directives to import namespaces and use [dependency injection](dependency-injection.md). Directives shared by many views might be specified in a common `_ViewImports.cshtml` file. The `_ViewImports` file supports the following directives:
107
107
108
108
*`@addTagHelper`
109
109
*`@removeTagHelper`
@@ -120,7 +120,7 @@ A sample `_ViewImports.cshtml` file:
The `_ViewImports.cshtml` file for an ASP.NET Core MVC app is typically placed in the *Pages* (or *Views*) folder. A `_ViewImports.cshtml` file can be placed within any folder, in which case it will only be applied to pages or views within that folder and its subfolders. `_ViewImports` files are processed starting at the root level and then for each folder leading up to the location of the page or view itself. `_ViewImports` settings specified at the root level may be overridden at the folder level.
123
+
The `_ViewImports.cshtml` file for an ASP.NET Core MVC app is typically placed in the *Pages* (or *Views*) folder. A `_ViewImports.cshtml` file can be placed within any folder, in which case it will only be applied to pages or views within that folder and its subfolders. `_ViewImports` files are processed starting at the root level and then for each folder leading up to the location of the page or view itself. `_ViewImports` settings specified at the root level might be overridden at the folder level.
124
124
125
125
For example, suppose:
126
126
@@ -131,12 +131,12 @@ Pages and views in the subfolder will have access to both Tag Helpers and the `M
131
131
132
132
If multiple `_ViewImports.cshtml` files are found in the file hierarchy, the combined behavior of the directives are:
133
133
134
-
*`@addTagHelper`, `@removeTagHelper`: all run, in order
135
-
*`@tagHelperPrefix`: the closest one to the view overrides any others
136
-
*`@model`: the closest one to the view overrides any others
137
-
*`@inherits`: the closest one to the view overrides any others
138
-
*`@using`: all are included; duplicates are ignored
139
-
*`@inject`: for each property, the closest one to the view overrides any others with the same property name
134
+
*`@addTagHelper`, `@removeTagHelper`: All run, in order.
135
+
*`@tagHelperPrefix`: The closest one to the view overrides any others.
136
+
*`@model`: The closest one to the view overrides any others.
137
+
*`@inherits`: The closest one to the view overrides any others.
138
+
*`@using`: All are included; duplicates are ignored.
139
+
*`@inject`: For each property, the closest one to the view overrides any others with the same property name.
140
140
141
141
<aname="viewstart"></a>
142
142
@@ -148,6 +148,6 @@ A sample `_ViewStart.cshtml` file:
The file above specifies that all views will use the `_Layout.cshtml` layout.
151
+
The preceding file specifies that all views will use the `_Layout.cshtml` layout.
152
152
153
153
`_ViewStart.cshtml` and `_ViewImports.cshtml` are **not** typically placed in the */Pages/Shared* (or */Views/Shared*) folder. The app-level versions of these files should be placed directly in the */Pages* (or */Views*) folder.
0 commit comments