Layout and Partial Views MIS 324 -- Professor Sandvig 11/15/2018 Layout and Partial Views MIS 324 Professor Sandvig
Overview Layout View Partial Views Define page layout once Inject dynamic content Partial Views Define “part of page” Use on multiple pages
MIS 324 -- Professor Sandvig 11/15/2018 Goal Reusable UI code Classes Code Reusability Modularity Interface Layout & Partial Views
Layout View Source: tutorialsTeacher.com
Layout View Layout view contains shared UI Current view injected: @RenderBody() Been using Layout View Views folder _ViewStart.cshtml
Layout View Three ways to specify which layout to use Layout Razor tag in each page In ActionMethod _ViewStart.cshtml
Layout View Action Method public ActionResult Index() { return View("Index", "_myLayoutPage"); }
Layout View _ViewStart.cshtml in View folder
Partial Views Reusable UI code Create like any other view Headers, footer, navigation, etc. Create like any other view Check Partial View Adds: Layout = null; Add to layout @Html.Partial("_header")
Partial Views Can fire action methods for dynamic content @Html.Action("_leftMenu") Example: Layout and Partial Views
MIS 324 -- Professor Sandvig 11/15/2018 Summary Benefits of Layouts & Partial Views Reusable UI code Easy to use