DRY out your MVC Views

 

For those of you that don’t know DRY : Don’t Repeat Yourself.

Take the following two screens

image

image

 

They are nearly identical.

MVC3/Razor provides two ways to make things DRYer.

1) Layouts (same as asp.net master pages, not covered in this post)

2) Partial views

Here’s how.

image

Shows the create page, using the Html.Partial extension method

 

image

Shows the edit page, using the Html.Partial extension method on the same partial view as well

 

image

Shows the partial view that gets injected (for want of a better word) into the two views shown previously.
Comments are closed