gpt4 book ai didi

c# - 在 _Layout.cshtml 中渲染 JavaScript 文件

转载 作者:行者123 更新时间:2023-12-02 17:36:20 26 4
gpt4 key购买 nike

我在 _Layout.cshtml 中渲染 JavaScript 文件时遇到问题。

@section Scripts {
<script src="@Url.Content("~/Scripts/Custom/productsSuggests.js")"></script>
}

当我将其粘贴到 Index.cshtml (Home) 时,它可以工作,但仅限于此页面。我需要这个脚本在全局范围内工作。我在 HomeViews 目录中有部分 View SearchBox,在 HomeController 中有 Controller 操作。

最佳答案

因为您位于 _Layout.cshtml View 中,所以它可能是顶级 View 。 部分是父 View 中的占位符。

尝试代替当前的代码

@Scripts.Render("~/Scripts/Custom/productsSuggests.js")

关于c# - 在 _Layout.cshtml 中渲染 JavaScript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36623295/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com