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.
I had this same problem appear once i had deployed my service, but could not replicate locally. For me the issue was that the View had None set for its build action. So the error was correct in that the file did not exist on the server, despite it existing in the repository.
Solution to fix this:
Using the wrong tilde can also produce this error.
Make sure you use the tilde "~" on your keyboard.
If you copied the code from a book, the tilde could be an invalid character (note that there are more than one tilde in Unicode).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With