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

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 thought on “ASP.NET MVC 3: Use Different Layout File in Razor View”

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