首页 > 解决方案 > 访问同一视图但使用路由对象时找不到数据表函数

问题描述

我有一个控制器操作,可让我通过单击直接位于 _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)

标签: jqueryasp.net-coredatatables

解决方案


推荐阅读