From the course: Learning ASP.NET Core MVC
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reuse shared HTML markup with layouts
From the course: Learning ASP.NET Core MVC
Reuse shared HTML markup with layouts
- [Instructor] Navigate around the Explore California site a little bit and notice how every single page contains the same common sections such as the header, footer and even the left side bar section of the page. This is a great thing as it gives a consistent look and feel throughout the site. However, it's really painful to change each instance of those common elements across all pages in the site. Luckily ASP.NET Core MVC allows us to define special Razor pages whose sole purpose it is to define this common layout and render content from individual pages inside of this layout. These types of Razor pages are referred to as layouts and they're a great candidate to live in that shared views folder we saw ASP.NET Core MVC looking for earlier. To demonstrate how they work, let's create the new Shared folder under the Views folder. Then I'll make a copy of our index.cshtml page into this new Share folder and rename it _Layout.cshtml. Now there's nothing special about the underscore or…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Render HTML with Razor3m 51s
-
(Locked)
Render dynamic content with Razor5m 1s
-
(Locked)
Reuse shared HTML markup with layouts3m 7s
-
(Locked)
Rendering reusable sections of content in a layout2m 34s
-
(Locked)
Pass data from the controller to the view1m 56s
-
(Locked)
Render data with strongly typed views2m 16s
-
-
-
-
-