简体   繁体   中英

MVC error Scripts not rendered for the layout page

I have an MVC application which was working fine. I made a few minor changes in one of the controllers and now I get the following error: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Scripts". The error is from the login page that had the following razor:

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

(the error goes away if comment this out).
I have the following bundle in my bundlesConfig file, (and is 'hit' when I debug the application and is listed as one of the bundles when I inspect the bundles in the watch window).

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate.unobtrusive.js",
                    "~/Scripts/jquery.validate.js"));

I can't figure out why I'm getting his problem as it was working and I haven't made any conscious changes to the login page or the bundlesConfig. (The global.asax file includes the line BundleConfig.RegisterBundles(BundleTable.Bundles);)

Thank you manthan. I did see that post before I submitted the question and it didn't help. I finally found a solution from this post: [link][1]

I added to my _Layout.cshtml page after the renderbody another line.

 <div class="container body-content">
    @RenderBody()
    @RenderSection("scripts", false)
 </div>

When I added the @Scripts.Render() to the individual pages, it was looking for the @RenderSection in the layout page. What I still don't understand is how this worked for 4 years without this line?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM