From the course: Learning ASP.NET Core MVC

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Reuse view markup with partial views

Reuse view markup with partial views

From the course: Learning ASP.NET Core MVC

Start my 1-month free trial

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…

Contents