以下部分已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“脚本”

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

提问人:عالي بخي 提问时间:2/16/2023 更新时间:3/8/2023 访问量:37

问:

我尝试通过@section脚本制作 Sctipt 部分,但没有措辞@section

@section Script {
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
    <script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="../../assets/js/visitManagement.js"></script>
}

在布局文件中:

    RenderSection("scripts",required:false);
Server Error in '/' Application.
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Script".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Script".

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Script".]

我重命名部分并重新运行项目,但未修复

asp.net asp.net-mvc-3

评论

0赞 CodeCaster 3/8/2023
scripts!= .Script

答:

-1赞 Manik 2/16/2023 #1

你失踪了@

 @RenderSection("Scripts", required: false)

在我的视图页面中

@section Scripts{
<script src="~/js/MyScript.js"></script>}