【问题标题】:Using Render Section script on MVC [duplicate]在 MVC 上使用渲染部分脚本 [重复]
【发布时间】:2016-05-28 19:54:38
【问题描述】:

我在下面的_Layout.cshtml 创建了两个渲染部分:

@RenderSection("scripts", required: false)
@RenderSection("scriptpartial", required: false)

Page Index.cshtml 使用来自_Layout.cshtml 的引用,在页面Index.cshtml 我使用定义代码:

@section scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            alert("This is code 1");
        });
    </script>
}

页面Index.cshtml包含一个部分_Other.cshtml,在文件_Other.cshtml我定义代码:

@section scriptpartial {
    <script type="text/javascript">
        $(document).ready(function () {
            alert("This is code 2");
        });
    </script>
}

当我运行应用程序时,只执行了“This is code 1”,我不知道这个错误

【问题讨论】:

  • @sections 在部分视图中被忽略。您必须从 _Layout 或 index 渲染它。

标签: jquery asp.net-mvc razor


【解决方案1】:

您必须将 scriptpartial 部分放在 Index.cshtml 页面上,因为不幸的是,@sections 在部分视图中是不可能的。

【讨论】:

    猜你喜欢
    • 2013-05-12
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 2015-02-02
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多