I want to exclude _layout for specific admin dashboard View. The only way I'm aware is with JS to hide those divs. Is there any other way?
CodePudding user response:
In the razor page for which you don't want to use a layout, you can do:
@{
Layout = null;
}
CodePudding user response:
If you want to exclude Layout from view temporarily, you can return view from a controller action using this code
if(...) return PartialView("name",model);
return View("name",model)
When you return a partial view, it will show only a view, no a layout
If your wont to exclude a layout permanenly for some views, you can use this code inside of the view
@{
Layout = null;
}
but don't forget that a Layout usually contains the most of Javascript and css libraries. So it is better to create a special layout for some views. or you can use ViewStart page
@{
string CurrentName = Convert.ToString(HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"]);
dynamic Layout;
switch (CurrentName)
{
case "User":
Layout = "~/Views/Shared/_Layout.cshtml";
break;
default:
//Admin layout
Layout = "~/Views/Shared/_AdminLayoutPage.cshtml";
break;
}
}