Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml"

I know there are a few questions that have been answered but I didn't find something specific to my case.

I'm using the mobile capabilities of MVC4. So I created a _layout.mobile.cshtml and the corresponding views.

The error above happens when I go in with a mobile device. As you can see, it is trying to display the regular _layout.cshtml instead of the _layout.mobile.cshtml. So I'm assuming it is also trying to display the view (say Index.mobile.cshtm) which doesn't have the section in question. Basically it is mixing the regular layout with the mobile views.

This doesn't happen all the time. If I recycle the pool it works again for a while and then all of the sudden it goes back to having the error and it will continue until I recycle the pool again.

Has anyone seen this problem before that can shed some light?

Thanks John

like image 260
John Truth Avatar asked May 24 '12 11:05

John Truth


3 Answers

In the _ViewStart.cshtml available under the Views folder, change the Layout value to your custom layout. I think this may help.. (Make sure that you are returning View instead of partial view)

for example

@{
Layout = "~/Views/Shared/_layout.mobile.cshtml";
}

In case if you want to change the layout for a specific page you can explicitly define it at the top of the page as a page directive.

like image 187
amesh Avatar answered Nov 20 '22 23:11

amesh


in the index.cshtml there is a section being called defined in the original layout file "_LayoutHome.cshtml" that is not defined in the new bootstrap layout.

specifically: @RenderSection("featured", required: false)

So the solution is to either add this section to the new layout (look for it in the original layout and paste it) or simply delete it from the index.cshtml.

like image 31
Rami Sarieddine Avatar answered Nov 20 '22 22:11

Rami Sarieddine


I had also face the same problem I removed

@section featured {

From View

like image 43
Alam Usmani Avatar answered Nov 20 '22 21:11

Alam Usmani