如果不使用模板页,在当前页中加入
@{
Layout = null;}
根据不同页面使用不同Layout
var controller = ViewContext.RouteData.Values["controller"].ToString().ToLower();
var action = ViewContext.RouteData.Values["action"].ToString().ToLower();
if (lController.Contains(controller)){
if (lAction.Contains(action))
{
Layout = "~/Views/Shared/_" + action + "_Layout.cshtml";
}else if (action == ""){
Layout = "~/Views/Shared/_Index_Layout.cshtml";
}
}
}