0

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.

2
  • 1
    Can you post the relevant code? Hard to trouble shoot without seeing what you've tried. Commented Aug 4, 2015 at 19:32
  • Is the view still trying to define the section for which you deleted the RenderSection? That's probably why. Commented Aug 4, 2015 at 19:32

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Or make it optional @RenderSection("Hello", required: false)
Ah, yes. Which I've done several times. Can't believe I forgot to mention that. Thanks @Jasen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.