The Partial tag helper is designed to replace the
Html.RenderPartial methods as the recommended mechanism for including partial pages in a Razor content page.
|The name of the partial file
|The model to be passed in to the partial view
|An expression to be evaluated against the current page model. Cannot be used in conjunction with the
ViewData dictionary to be passed to the partial view
The partial tag helper will always load the partial content asynchronously.
name attribute will search all registered partial locations for a file with the supplied name (without the extension). The following example will search for _MyPartial.cshtml in Pages, Pages/Shared and Views/Shared by default:
<partial name="_MyPartial" ... />
You can provide a partial path, which will be appended to the search locations:
<partial name="Folder1/_MyPartial" ... />
Now the framework will search for the following:
model attribute and the
for attribute both provide a means to pass data to the Partial. You can use one or the other but not both. The examples that follow illustrating the difference both assume that the current PageModel has a
<partial name="_MyPartial" model="Model.Contacts" />
<partial name="_MyPartial" for="@Model.Contacts" />
<partial name="_MyPartial" for="Contacts" />
The last two examples are equivalent. The
@Model part of the expression is inferred in the second approach.