Layout and Partial Views MIS 324 -- Professor Sandvig 2/28/2019 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 2/28/2019 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 _ViewStart.cshtml Layout Razor tag in each page In ActionMethod
Layout View _ViewStart.cshtml in View folder
Layout View Action Method public ActionResult Index() { return View("Index", "_myLayoutPage"); }
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 2/28/2019 Summary Benefits of Layouts & Partial Views Reusable UI code Easy to use