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
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 fllow illustrating the difference both assume that the current pagemodel has a
<partial name="_MyPartial" model="Model.Contacts" />
<partial name="_MyPartial" for="@Model.Contacts" /> or <partial name="_MyPartial" for="Contacts" />
The last two examples are equivalent. The
@Model part of the expression is inferred in the second approach.