Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Layout will default to _ViewStart, so why section name is not found?

Let's say I have this view:

@model App.ViewModels.Unicorn

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

<div id='#unicorns'>...</div>

@section Scripts {
    @Scripts.Render("~/bundles/unicorns")
}

If removing the Layout in the view will default it's layout to the one specified in the _ViewStart.cshtml file then why is it complaining about Cannot resolve section 'Scripts'?

EDIT: I do have my section on my layout page:

@RenderSection("scripts", required: false)

Please do note this is not case sensitive, since it's been working with the @section Scripts uppercase 'S' and @RenderSection("scripts lower 's'.

like image 555
Esteban Avatar asked Oct 21 '22 09:10

Esteban


1 Answers

Even though .Net doesn't care about the case sensitivity Resharper does. Changing it to lowercase will fix the issue.

@section scripts {
    @Scripts.Render("~/bundles/unicorns")
}
like image 82
SavoryBytes Avatar answered Nov 18 '22 06:11

SavoryBytes