如何在cshtml文件中调用外部javascript文件

如何在cshtml文件中调用外部javascript文件,javascript,asp.net-mvc,razor,Javascript,Asp.net Mvc,Razor,下面是我的Javascript文件 Copy.js function CopyYourSheet() { var ifrm = document.createElement("iframe"); ifrm.setAttribute("src", "https://docs.google.com/spreadsheets/d/1992ry0dpIjel_TQuB-W6fb2Nd7uST69AX_jY/edit#"); ifrm.style.width = "10000px

下面是我的Javascript文件

Copy.js

function CopyYourSheet() {

    var ifrm = document.createElement("iframe");
    ifrm.setAttribute("src", "https://docs.google.com/spreadsheets/d/1992ry0dpIjel_TQuB-W6fb2Nd7uST69AX_jY/edit#");
    ifrm.style.width = "10000px";
    ifrm.style.height = "2000px";
    document.body.appendChild(ifrm);
    }
下面是CSHTML文件

Index.cshtml

@{
    ViewData["Title"] = "Home Page";
}

    <div class="text-center">
        <h1 class="display-4">Welcome</h1>                    
        <button id="CopyYourSheet" onclick="CopyYourSheet()">Get your details</button>
    </div>
@{
ViewData[“Title”]=“主页”;
}
欢迎
获取您的详细信息

正确的方法是将Copy.js捆绑到您的捆绑包中

在App_开始文件夹下打开BundleConfig

然后加上

bundles.Add(new ScriptBundle("~/bundles/myjs").Include(
                        "~/Scripts/copy.js"));
然后像这样将其包含在主视图中

@Scripts.Render("~/bundles/myjs")
如果您没有App_Start文件夹,或者您不喜欢捆绑在MVC项目中,那么请将脚本包含在布局局部视图的
标记中。最好将其添加到结束标记的正上方

<script src="~/Scripts/copy.js"></script>


确保文件的路径正确。如果js文件位于主项目树中,则可能需要删除src路径中的/Scripts/文件夹。~应该保留在路径的开头,以便在代码从不同环境运行时灵活使用。

谢谢。但我无法找到此应用程序启动文件夹。我使用的是最新版本。请帮助我获取此信息。我已编辑了备选解决方案的答案,以包含脚本。如果这解决了您的问题,请接受答案。谢谢