skip to Main Content

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?

2

Answers


  1. In the razor page for which you don’t want to use a layout, you can do:

    @{
        Layout = null;
    }
    
    Login or Signup to reply.
  2. 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;  
        }  
    }   
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search