Попробуйте это:
Действие
public ActionResult Index() {
ViewBag.Layout = null;
object layout;
if (RouteData.Values.TryGetValue("layout", out layout)) {
switch(layout.ToString())
{
case "Layout1":
ViewBag.Layout = "~/Views/Shared/_Layout.cshtml";
break;
// ...
}
}
return PartialView("Test");
}
Разметка
@{
Layout = ViewBag.Layout;
}
<div>This is the test page...</div>
Конфигурация маршрутизации
routes.MapRoute(
"Default", // Route name
"{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // Parameter defaults
routes.MapRoute(
"DefaultWithLayout", // Route name
"{layout}/{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // Parameter defaults
}
Или просто
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{layout}", // URL with parameters
new { controller = "Home", action = "Index", layout = UrlParameter.Optional, id = UrlParameter.Optional }); // Parameter defaults