The Partial Tag Helper renders a named partial view inside a Razor file. Partial views split large pages into reusable HTML sections without handling requests, model binding, validation, or application logic. section 17.4.3
Render a reusable to-do item
Create _ToDo.cshtml with @model ToDoItemViewModel and markup for the title and tasks. A Razor Page can then render it for each recent item: <partial name="_ToDo" model="todo" />. section 17.4.3
Listing 17.12 Partial view _ToDo.cshtml for displaying a ToDoItemViewModel
@model ToDoItemViewModel #1
<h2>@Model.Title</h2> #2
<ul> #2
@foreach (var task in Model.Tasks) #2
{ #2
<li>@task</li> #2
} #2
</ul> #2
Shows the partial view’s model declaration and its Razor markup for displaying a to-do item. section 17.4.3
Listing 17.13 Rendering a partial view from a Razor Page
@page #1
@model RecentToDoListModel #2
@foreach(var todo in Model.RecentItems) #3
{
<partial name="_ToDo" model="todo" /> #4
}
Shows a Razor Page looping through recent items and passing each item to the named partial. section 17.4.3
