Calling a View does not load the _Layout.cshtml RRS feed

  • Question

  • User248267340 posted

    I'm fairly new to MVC Core 2.2, but I have seen this problem before.

    1. I have an Area named "Main"
    2. I have a controller named "MainController.cs"
    3. The code inside the controller has 2 methods:

    public IActionResult Index()
    return View();

    public IActionResult BlankPage()
    return View();

    5. I have a folder "Areas/Main/Views", which contains the _Layout.cshtml file and the _ViewStart.cshtml file. The contents in the ViewStart file is:

    Layout = "~/Areas/Main/Views/_Layout.cshtml";

    The Layout uses the default wwwroot/css

    6. I have the "Areas/Main/Views/Main" folder set up properly, with two files inside: Index.cshtml, and BlankPage.cshtml

    7. The file "Index.cshtml" is the default, and it is loaded directly from the Startup.cs file.

    8. Inside the Index.cshtml file, I included the following line of code:

                    <a asp-area="Main" asp-controller="Home" asp-action="BlankPage">Blank Page</a>

    When I start the project, Index.cshtml loads great. It loads the css contents and I can view a beautiful page.

    Here's the bad news: when I click on the above link to load the BlankPage.cshtml file, the browser shows the correct path to the BlankPage, but there's no content. There's no css or html being loaded at all.

    When I view the source (Tools/Web Developer/Page Source) it's completely empty.

    Do you have idea what I can do to fix that?

    Monday, March 18, 2019 7:36 PM


All replies