MVC Master Pages and Custom Controls

Being from WebForms background, I want to “translate” MVC terms to WebForms speak:

– MVC Partial pages –> WebForms UserControls

– MVC Layout pages –> WebForms Master pages


Partial Page example:

1. On the Shared folder, select Add Item –> MVC 3  Partial Page(Razor)



The page itself can be any CSHTML, as shown here:


2. Use this page as part of your View or Layout as below:




Layout Page example:

1. On the Shared Folder, select Add Item –> MVC3 Layout Page (Razor)


– The layout page can be any CSHTML but it needs to call @RenderBody() method somewhere.

– If you want to inherit the default layout use

@{       Layout = "~/Views/Shared/_Layout.cshtml";

Here’s a sample code:



2. This layout can be used in a view by using the Layout property above.



About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: