1

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

2

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

1

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

0

Instead of:

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

Try this:

@{ 
   Layout = null;
}
-1

In Solution Explorer, right click on the Shared folder, then Publish Shared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.