I get the error: The layout page "_Layout" could not be found at the following path: "~/Views/Home/_Layout".
But layout page is at this path: "~/Views/Shared/_Layout"
What can it be for problem?
I just started the project and it look like this:
Controller:
namespace Testing.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
}
Index view:
@model dynamic
@{
ViewBag.Title = "title";
Layout = "_Layout";
}
<h2>title</h2>
_ViewStart.cshtml:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Solution Explorer:
Make sure that in your ~/Views/_ViewStart.cshtml
file you have set the correct path:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Also if in your views you are overriding the layout ensure that the proper path is specifid for this layout. And in addition to that there could be some server side code which is setting the layout (such as custom action filters, or the ViewResult
overload which allows to specify a layout, ...).
UPDATE:
You seem to have set the Layout like this:
@{
ViewBag.Title = "title";
Layout = "_Layout";
}
You need to specify the location to the layout as absolute path:
@{
ViewBag.Title = "title";
Layout = "~/Views/Shared/_Layout.cshtml";
}
But an even better way is to get rid of this Layout setting in your Index
view:
@{
ViewBag.Title = "title";
}
Now the value from your _ViewStart.cshtml
will be used.
Yes, I have it like this
I have listed other possible reasons in my answer. Did you check them all?
It shouldn't be, I just started the project
that was the problem! Thanks! It's a bit confusing that generated code had Layout = "_Layout"; Thanks again =)
It's true, although possibly mostly for Resharper users. The first thing you get after creating a new controller and view using the Resharper shortcuts is the line Layout="_Layout" which immediately had me thinking, "Great! It knows where to look for templates and knows what file extension to look for." But it doesn't. So I too got OP's error message out of the box.