From the course: Learning ASP.NET Core MVC
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Reuse view markup with partial views
From the course: Learning ASP.NET Core MVC
Reuse view markup with partial views
- [Instructor] In this chapter, I'll show you how to create reusable components to help centralize your logic in markup, making it easier to maintain your application in the long run. I'll start in this video with a technique called partial views. Put simply, partial views allow you to take chunks of your views and put them in their own separate files, and then stitch them back together again to create full views, allowing you to reuse markup in multiple places throughout your application. In fact, we've already seen a perfect example in which this would be really helpful. We used the same markup to display posts in both the list view on the blog's homepage in Index.cshtml and the full post view in Post.cshtml. Now, assuming that I want the blog post markup shown in the homepage to look exactly like the blog post markup shown in the individual post page, what I really want to do is create one partial view that both of them can share. To do this, I'll create a brand new view, and…
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
-
-
-
-
-
-
-
(Locked)
Reuse view markup with partial views4m 13s
-
(Locked)
Reuse view logic with injectable services3m 16s
-
(Locked)
Creating reusable components with view components4m 51s
-
(Locked)
Enhancing a view component with logic and dynamic markup4m 15s
-
(Locked)
Avoid page refreshes with partial rendering5m 8s
-
(Locked)
-
-