【发布时间】:2019-11-15 13:03:27
【问题描述】:
我无法在我的 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: http://prntscr.com/oapg36
【问题讨论】:
-
你想从
site.js调用什么函数?不工作是什么意思?您是否在 Web 浏览器开发人员工具中收到任何错误?对于site.js,它将由.net core 和Pages/Shared/_Layout.cshtml和<script src="~/js/site.js" asp-append-version="true"></script>自动加载。
标签: javascript asp.net-core .net-core razor-pages