DRY out your MVC Views
For those of you that don’t know DRY: Don’t Repeat Yourself.
Take the following two screens.
![]()
![]()
They are nearly identical.
MVC3/Razor provides two ways to make things DRYer.
-
Layouts (same as ASP.NET master pages, not covered in this post)
-
Partial views
Here’s how.
![]()
Shows the create page, using the Html.Partial extension method
![]()
Shows the edit page, using the Html.Partial extension method on the same partial view as well
![]()