The layout page "~/Views/Shared/_Layout.cshtml" could not be found

12,309

Solution 1

if you rename your project you can get that error. Solution is simple. Just remove tilda (~) -> /View/.... instead of ~/View..., also in your _Layout file remove tilda from all links

Solution 2

Search for '_Layout.cshtml' in Solution Explorer (righthand side). Then you will find _Layout.cshtml. Right click on the file and click 'Scope to This'.

Voila! All your missing files will be visible under 'Shared' folder. Dont know why exactly this happens.

Solution 3

In case someone is interested or had the same problem. It seems this may be a problem with the server (hence, why it runs fine in localhost) :) But anyway, if it happens to you, do this:

  1. duplicate the layout and rename it Layout2
  2. change its call in the ViewStart.cshtml so the right layout is called per page
  3. Go to Azure or whoever is your server and delete everything.
  4. recreate your directory
  5. Go back to VS and clean, build, and publish

And you should be good to go

Share:
12,309

Related videos on Youtube

Prashant
Author by

Prashant

Updated on September 18, 2022

Comments

  • Prashant
    Prashant over 1 year

    I got this error and I can't figure out what is going on. I am positive the _layout.cshtml resides in the shared folder and for the sake of trying things out, I moved to the Home folder and it then told that the Views/Home/_Layout.cshtml couldn't be found there either. So now I'm thinking the problem is in the call for this file for some reason.

    I'm not going to pretend I know ASP.NET MVC4, so please when you answer, explain it as you would to someone who is not familiar with the system at all. Believe it or not, this error came from tutorial #1 ha ha

    Here's the code to show that I did code it right:

    @{
       ViewBag.Title = "Home Page";
       Layout = "~/Views/Shared/_Layout.cshtml";
    }
    

    And here is a picture of the location

    enter image description here

    p.s. I did my research, Google has nothing and there is another question here but it was asked on 2008 with MVC3 which is completely different

    I am running ASP.NET MVC4 on Azure

    Thanks

  • dan
    dan over 5 years
    Please use code formatting, otherwise it won't be displayed properly.