如何处理异常“以下部分已定义但未在布局中呈现”

本文关键字:定义 布局 处理 何处理 异常 下部 | 更新日期: 2023-09-27 18:33:37

我遇到了一个问题,由于搜索,我发现在我的布局中放置了一个@RenderSection("SectionName"),但即使异常只是弹出,也不知道如何处理它。这是我认为定义的部分。

@section scripts{
    <script src="~/Scripts/infiniteScroll.js"></script>
    <script type="text/javascript">
        $(function () {
            $("div#loading").hide();
        });
        var moreRowsUrl = "/InfiniteScrollDemo/GetCustomers"; //the URL to your ActionMethod
        //var moreRowsUrl = ' Url.RouteUrl("CustomerList")'; //if you have a route defined, you can use an Html helper like Url.RouteUrl
        $(window).scroll(scrollHandler);
</script>
}

这是布局代码:

@using Microsoft.AspNet.Identity

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="The First Online Shopping Mall in Afghanistan">
    <meta name="author" content="Naser Dostdar">
    <title>@ViewBag.Title Online Shopping Center</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/font-awesome.min.css" rel="stylesheet" />
    <link href="~/Content/prettyPhoto.css" rel="stylesheet" />
    <link href="~/Content/price-range.css" rel="stylesheet" />
    <link href="~/Content/animate.css" rel="stylesheet" />
    <link href="~/Content/main.css" rel="stylesheet" />
    <link href="~/Content/responsive.css" rel="stylesheet" />
    <link rel="shortcut icon" href="images/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch-icon-57-precomposed.png">
</head>

<body>
    <div>
        @RenderBody()
    </div>
    @RenderSection("scripts")

        <script src="~/Scripts/jquery.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>
        <script src="~/Scripts/jquery.scrollUp.min.js"></script>
        <script src="~/Scripts/price-range.js"></script>
        <script src="~/Scripts/jquery.prettyPhoto.js"></script>
        <script src="~/Scripts/main.js"></script>
        <script src="~/Scripts/jquery-1.10.2.js"></script>
        <script src="~/Scripts/jquery.validate.js"></script>
        <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
</body>
</html>

任何建议或提示将不胜感激,提前感谢。

编辑 1:当我将布局添加到视图中时,我的视图未使用布局,另一个错误出现。错误是未定义部分:"脚本"。

如何处理异常“以下部分已定义但未在布局中呈现”

如果你有一个可选的部分,你需要在required标志设置为 false 的情况下呈现它:

@RenderSection("scripts", required: false)