user3802248
user3802248

Reputation: 39

ASP.NET MVC custom _Layout.cshtml

Visual Studio creates a defualt _Layout.cshtml And I am trying to make different design; however, when the RenderSection() \code is deleted, the browser shows an error. It does not load. Can anyone show help me how to do it.

Upvotes: 0

Views: 230

Answers (1)

James R.
James R.

Reputation: 840

If your view is trying to define a section such as:

@section Hello
{
    <p>Hello</p>
}

And your _Layout never renders it:

@RenderSection("Hello")

Then you will get an exception such as:

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

You must call RenderSection for all sections that your views define, or remove the sections from the view.

Upvotes: 2

Related Questions