即Index对应 _Index_Layout, Edit对应_Index_Layout...
@{
var controller =
ViewContext.RouteData.Values["controller"].ToString().ToLower();
var action =
ViewContext.RouteData.Values["action"].ToString().ToLower();
string[] lController = new string[] { "user",
"news", "mail" };
string[] lAction = new string[] { "index", "edit",
"create" };
if (lController.Contains(controller)){
if
(lAction.Contains(action))
{
Layout
= "~/Views/Shared/_" + action + "_Layout.cshtml";
}else if (action ==
""){
Layout
= "~/Views/Shared/_Index_Layout.cshtml";
}
}
}