Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从razorpage调用另一个目录中的javascript函数_Javascript_Asp.net Core_.net Core_Razor Pages - Fatal编程技术网

从razorpage调用另一个目录中的javascript函数

从razorpage调用另一个目录中的javascript函数,javascript,asp.net-core,.net-core,razor-pages,Javascript,Asp.net Core,.net Core,Razor Pages,我不能在razorpages项目中包含javascript文件。我希望能够从中调用函数,但即使警报也无法工作 我已经包括app.UseStaticFiles;在startup.cs中 我的html是这样的: @page @model OptimalHousing.Pages.IndexModel @{ ViewData["Title"] = "Index"; } <head> <script type="text/javascript" sr

我不能在razorpages项目中包含javascript文件。我希望能够从中调用函数,但即使警报也无法工作

我已经包括app.UseStaticFiles;在startup.cs中

我的html是这样的:

@page
@model OptimalHousing.Pages.IndexModel

@{
    ViewData["Title"] = "Index";
}

    <head>
        <script type="text/javascript" src="~/js/site.js"></script>
    </head>
<h1>Index</h1>

<p>
    <a asp-page="Create">Create New</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Dorm[0].dormName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Dorm[0].dormUrl)
            </th>
            <th></th>
        </tr>

    </thead>
    <tbody>
        @foreach (var item in Model.Dorm)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.dormName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.dormUrl)
                </td>
                <td>
                    <a asp-page="./Edit" asp-route-id="@item.id">Edit</a> |
                    <a asp-page="./Details" asp-route-id="@item.id">Details</a> |
                    <a asp-page="./Delete" asp-route-id="@item.id">Delete</a> |
                    <a asp-page="./GetAddress" asp-route-id="@item.id">Get address</a>
                    <input type="button" id="getSearchresultsButton" name="getCoordinates" value="Get searchresults" onclick="callGetFilteredDorms()" />
                </td>
            </tr>
        }
    </tbody>

</table>
<input type="button" id="getSearchresultsButton" value="Get searchresults" onclick="javascript: dope()" /> 
我尝试包含的文件是此目录结构中的site.js:
在你的页面中要考虑一些不同的事情。首先,我认为您需要一个包含所有基本HTML标记的结构:

<html lang="en">
    <head>
      <meta charset="utf-8">
      <script type="text/javascript" src="js/site.js"></script>
    </head>

    <body>
        {{PUT YOUR BODY HTML HERE}}
    </body>
</html>
你得到实际的javascript文件了吗?如果没有,则它没有正确映射,您需要修复配置

如果是这样的话,我认为上面这一行是这样的:

<script type="text/javascript" src="js/site.js"></script>
应该对你有用


我在C代码中看到的另一件事是,使用数组的第一个元素作为表头,然后迭代同一个Dorm数组。这将打印相同的第一个元素两次。考虑将表标题放在它们自己的变量中,而不是将它们存储在数组中。 您想从site.js调用什么函数?你说不工作是什么意思?您是否收到web浏览器开发工具中的任何错误?对于site.js,它将由.net core通过Pages/Shared/_Layout.cshtml自动加载。添加正确的html结构是有效的,它没有包含在microsoft站点的教程中,因此我认为没有必要,谢谢。
<script type="text/javascript" src="js/site.js"></script>