The layout page "~/Views/Shared/_Layout.cshtml" could not be found at
the following path: "~/Views/Shared/_Layout.cshtml".
I am getting the above error from the _ViewState.cshtml
It was coming while I execute it through my Home Controller.
I have got to see some link for resolving this program but it is not happening. Could you people help me out on this
If you have your code like this
#{
ViewBag.Title = "title";
Layout = "_Layout";
}
Then make sure that in your ~/Views/_ViewStart.cshtml file you have set the correct path
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
The error message tells you exactly what is the problem.
Check the Views/Shared Folder and make sure the _Layout.cshtml is actually there.
The build action of that file should be Content
Related
I have layout and use this in two page and when i change page layout don't work
why this is happening?
Layout = "~/Views/Shared/_Layout.cshtml";
I use this code for pages
On the new page (a .cshtml file a.k.a a view in the MVC site architecture), make sure you have specified which layout you are using in an ASP.NET code block.
Such as:
#{
Layout = "_Layout";
}
the #{} is important in the above code. Also, if you haven't renamed the layout, you should just be able to write it as I specified, instead of having to do Layout = "~/Views/Shared/_Layout.cshtml";
My layout name is = _DefaultLayout.
Controller:
_ViewStart:
Index.cshtml:
The CSS is not loaded in this page, but on another page it is loaded.
Please help my to fix this problem
Thanks
Seem like typo problem. The suffix for layout code is predefined. Therefore, change _DefaultLayout.csshtml to _DefaultLayout.cshtml.
Then in the _ViewStart.cshtml you can write:
#{
Layout = "~/Views/Shared/_DefaultLayout.cshtml";
}
And check that Build Action property of the _DefaultLayout.cshtml file is set to Content.
For additional information see: Layout in ASP.NET Core
I'm creating a new view and I want to add some custom CSS, so I created a new CSS sheet in the content folder called ClientDetails and referenced it at the top of the sheet as I read on another thread of adding specific CSS sheets to a view:
#model Linkofy.Models.Client
#{
ViewBag.Title = "Details";
}
#section Styles {
<link href="#Url.Content("~/Content/ClientDetails.css")" rel="stylesheet" type="text/css" />
}
<h2>#Html.DisplayFor(model => model.clientN)</h2>
However with the #section Styles bit I get this error:
System.Web.HttpException: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Styles".
Though if I remove the #section styles bit it works fine, I wondered if its only rendering that sheet and not the layout CSS if it's overriding it or something? how do I add it on top of all the other sheets needed for the display.
I have tried looking around for the answer to this though if it is a duplicate please link me to the question and I will close it, thanks!
Problem:
Server Error in '/' Application.
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Styles".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Styles".
Solution:
In your ~/Views/Shared/_Layout.cshtml render the section using
#RenderSection("Styles", required: false)
See https://msdn.microsoft.com/en-us/library/gg537886(v=vs.111).aspx for more details.
Also you must declare the layout:
#{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Details";
}
The reason you are getting this error is explained in the message. You probably have something like this in your layout page:
#RenderSection("Styles")
When you use it like that, it's required by default. Every page will be required to have the additional style section. Otherwise, you get the error you are seeing now. What you need to do is make that section not required:
#RenderSection("Styles", required: false)
I have a view with the following reference at the top of the view as shown below.
#using MVC_Application.ViewModels.SPA;
#Model MainViewModel;
#{
Layout = null;
ViewBag.Title = "Index";
}
When this view is viewed on a browser I do see the reference shown on browser as MVC_Application.ViewModels.SPA.MainViewModel MainViewModel; at the top of the screen and rest of the View is displayed as expected.
Can someone please tell me how to remove this reference when View is viewed on a browser.
You are trying to use the model directive by using an uppercase M. That is the instance of the model passed in which is why you see the typename output and then the plain text of MainViewModel following it. Simply change your directive to this:
#model MainViewModel
Note: The semicolons are not needed
Bonus: You could also get rid of the #using line by specifying the full model namespace (assuming the rest of the view doesn't rely on it):
#model MVC_Application.ViewModels.SPA.MainViewModel
I have an MVC4 web application that i'm adjusting. Currently a controller loads Index.cshtml. In that file i have the following line:
#{
Layout = "~/Views/Shared/_Layout-DoubleColumn.cshtml";
}
So i changed that line to:
#{
Layout = "~/Views/Shared/_Layout-TripleColumn.cshtml";
}
I also copied to _Layout-DoubleColumn.cshtml file and renamed that to _Layout-TripleColumn.cshtml.
Now when i run the application i get the following error message:
The layout page "~/Views/Shared/_Layout-TripleColumn.cshtml" could not
be found at the following path:
"~/Views/Shared/_Layout-TripleColumn.cshtml"
I have no clue what the problem could be, because i'm sure that the file is in the Shared folder...
Anyone any idea what the problem could be?
Make sure the Build Action of the file is set to Content in the properties of the View.