访问同一视图但使用路由对象

时间:2019-12-06 14:02:19

标签: jquery .net asp.net-mvc datatables core

我有一个控制器操作,可通过单击直接位于_layout.cshtml内部的导航栏菜单选项(路由为/Mock/ManageMock)或@Renderbody中的按钮来访问ManageMock.cshtml。 )的_layout.cshtml(路由例如为/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中有了这个

<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)

0 个答案:

没有答案