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/views/partial.md
+30-3Lines changed: 30 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ author: ardalis
4
4
description: Discover how to use partial views to break up large markup files and reduce the duplication of common markup across web pages in ASP.NET Core apps.
5
5
ms.author: riande
6
6
ms.custom: mvc
7
-
ms.date: 04/06/2019
7
+
ms.date: 06/12/2019
8
8
uid: mvc/views/partial
9
9
---
10
10
# Partial views in ASP.NET Core
@@ -42,7 +42,7 @@ Don't use a partial view where complex rendering logic or code execution is requ
42
42
43
43
A partial view is a *.cshtml* markup file maintained within the *Views* folder (MVC) or *Pages* folder (Razor Pages).
44
44
45
-
In ASP.NET Core MVC, a controller's <xref:Microsoft.AspNetCore.Mvc.ViewResult> is capable of returning either a view or a partial view. In Razor Pages, a <xref:Microsoft.AspNetCore.Mvc.RazorPages.PageModel> can return a <xref:Microsoft.AspNetCore.Mvc.PartialViewResult>. Referencing and rendering partial views is described in the [Reference a partial view](#reference-a-partial-view) section.
45
+
In ASP.NET Core MVC, a controller's <xref:Microsoft.AspNetCore.Mvc.ViewResult> is capable of returning either a view or a partial view. In Razor Pages, a <xref:Microsoft.AspNetCore.Mvc.RazorPages.PageModel> can return a partial view represented as a <xref:Microsoft.AspNetCore.Mvc.PartialViewResult> object. Referencing and rendering partial views is described in the [Reference a partial view](#reference-a-partial-view) section.
46
46
47
47
Unlike MVC view or page rendering, a partial view doesn't run *_ViewStart.cshtml*. For more information on *_ViewStart.cshtml*, see <xref:mvc/views/layout>.
48
48
@@ -54,7 +54,7 @@ Partial view file names often begin with an underscore (`_`). This naming conven
54
54
55
55
A partial view is a *.cshtml* markup file maintained within the *Views* folder.
56
56
57
-
A controller's <xref:Microsoft.AspNetCore.Mvc.ViewResult> is capable of returning either a view or a partial view.
57
+
A controller's <xref:Microsoft.AspNetCore.Mvc.ViewResult> is capable of returning either a view or a partial view. Referencing and rendering partial views is described in the [Reference a partial view](#reference-a-partial-view) section.
58
58
59
59
Unlike MVC view rendering, a partial view doesn't run *_ViewStart.cshtml*. For more information on *_ViewStart.cshtml*, see <xref:mvc/views/layout>.
60
60
@@ -64,6 +64,33 @@ Partial view file names often begin with an underscore (`_`). This naming conven
64
64
65
65
## Reference a partial view
66
66
67
+
::: moniker range=">= aspnetcore-2.0"
68
+
69
+
### Use a partial view in a Razor Pages PageModel
70
+
71
+
In ASP.NET Core 2.0 or 2.1, the following handler method renders the *\_AuthorPartialRP.cshtml* partial view to the response:
72
+
73
+
```csharp
74
+
publicIActionResultOnGetPartial() =>
75
+
newPartialViewResult
76
+
{
77
+
ViewName="_AuthorPartialRP",
78
+
ViewData=ViewData,
79
+
};
80
+
```
81
+
82
+
::: moniker-end
83
+
84
+
::: moniker range=">= aspnetcore-2.2"
85
+
86
+
In ASP.NET Core 2.2 or later, a handler method can alternatively call the <xref:Microsoft.AspNetCore.Mvc.RazorPages.PageBase.Partial*> method to produce a `PartialViewResult` object:
Within a markup file, there are several ways to reference a partial view. We recommend that apps use one of the following asynchronous rendering approaches:
0 commit comments