jquery - 访问同一视图但使用路由对象时找不到数据表函数
问题描述
我有一个控制器操作,可让我通过单击直接位于 _layout.cshtml 内部的导航栏菜单选项/Mock/ManageMock
(路径为例如/Mock/ManageMock/2
)
public async Task<IActionResult> ManageMock(int? id)
{
List<SiteViewModel> sites = await _siteService.List();
if (id != null)
{
ViewBag.LoadSite = id;
}
return View(sites);
}
当我去时/Mock/ManageMock
,数据表运行良好。我没有收到任何错误
当我去时/Mock/ManageMock/2
,我得到:
Uncaught TypeError: $(...).DataTable is not a function
Uncaught TypeError: $(...).tabs is not a function
这是为什么?
我有这个_Layout.cshtml
,就在 body 的结束标签之前
<environment include="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"
integrity="sha256-eEa1kEtgK9ZL6h60VXwDsJ2rxYCwfxi40VZ9E0XwoEA="
crossorigin="anonymous"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.18/b-1.5.6/datatables.min.js"></script>
</environment>
<environment exclude="Development">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery"
crossorigin="anonymous"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
crossorigin="anonymous"
integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o">
</script>
</environment>
@RenderSection("Scripts", required: false)
解决方案
推荐阅读
- qt - 是否有可以嵌入到应用程序中的 vscode QT 小部件
- grep - grep -o search 在第二个表达式的第一个实例处停止,而不是最后一个?贪婪的?
- java - Spring应用程序没有在MySQL上创建表
- sql - 获取无效数字,值“_”,位置 2,类型:运行选择查询时的整数
- c# - 在 C# 中使用正则表达式查找 3 个或更多空格
- html - 模仿 Bootstrap 的网页导航栏(使用 Angular)
- reactjs - 避免使用 react hooks 重新渲染
- ms-access - 在 Microsoft Access 表单中添加记录而不显示/编辑其他记录
- javascript - 将标记添加到 jQuery 插件内的 Google 地图
- azure-eventgrid - Azure 事件网格 - 不匹配事件的日志