ASP.NET Core MVC: _ViewStart.cshtml

Jerry Lipan 916 Reputation points
2022-06-04T21:16:39.197+00:00

Hello,

In my ASP.NET Core Project, _Layout file I make into 2 files

  1. _Layout.cshtml
  2. _LayoutDashboard.cshtml

208424-05062022-001.png

It is made this way so

  1. Controller Name: Home. Default Page which is a Home Page it will read _Layout.cshtml.
  2. Controller Name: Dashboard. So, the Page after logon, it will read _LayoutDashboard.cshtml.
  3. Others Controller is No Layout

Is this the best practice ? If have better way, please shere

Please help

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 12,666 Reputation points
    2022-06-05T05:36:28.573+00:00

    Your approach is perfectly fine.

    The other option is to set a default layout in the viewstart and then override the Layout in those pages where you want to use the other layout

      @{
            Layout = "_Layout";
        }
    

    Refer: https://www.learnrazorpages.com/razor-pages/files/layout

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.