Skip to content

Include (aka Partial)

Ivan Balan edited this page Aug 27, 2016 · 1 revision

Include

Include feature is useful when you have reusable parts of your templates you want to share between different views

When Should I Use Includes

Includes are an effective way of breaking up large templates into smaller components. They can reduce duplication of template content and allow elements to be reused.

Example

@model MyProject.TestViewModel
<div>
    Hello @Model.Title
</div>

@{ await IncludeAsync("SomeView.cshtml", Model); }

First argument takes a key of the template to resolve, second argument is a model of the view (can be null)