RSS

ASP.NET MVC 3: Use Different Layout File in Razor View

07 May

There are two ways to use different layout files in MVC view.

1. Set Layout in the View.

Create a new layout file in Shared folder and set the layout in the view page, on the top. Here part of my Index.cshtml.

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

2. Use Controller to Set Layout

Create new layout page and return the layout file in the controller. Here’s my AdminController.cs

public ActionResult Index()
{
    return View("Index", "_LayoutAdmin");
}
Advertisements
 
1 Comment

Posted by on May 7, 2011 in General

 

Tags: , , ,

One response to “ASP.NET MVC 3: Use Different Layout File in Razor View

  1. Mohammad

    June 10, 2011 at 12:39 am

    Thank you

     

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: