MVC 3 - RAZOR VIEWS - C # - Separate _Layout.cshtml for home page from other pages on site

How do you create a separate _layout.cshtml file for the HomePage design that is not rendered in the same way as internal pages.

eg. - - Home Page Template I don't want to use the slider at the top for inner content pages.

Is it possible to call one _layout.cshtml for the master page; Calling another _layout-content.cshtml for content pages?

What would be the appropriate syntax for this?


source to share

1 answer

One way is to override the layout in the view you want.


  Layout = "~/Views/Shared/_layout.cshtml";


Or you can do this in your controller


public ActionResult Index()
  ViewResult result = this.View();
  // i think this is correct and it shouldn't need a full/relative path
  result.MasterName = "_layout.cshtml";       
  return result;


This assumes that your _ViewStart.cshtml files look like this:

  Layout = "~/Views/Shared/_layout-content.cshtml ";




All Articles