簡體   English   中英

_Layout.cshtml和我的ViewFile.cshtml之間有什么相互作用?

[英]What is the interaction between _Layout.cshtml and my ViewFile.cshtml?

在_Layout.cshtml中,有對jQuery和bootstrap.min.js的引用。 但是,在ViewFile頁面上,除非包含對jQuery和數據表的引用,否則我無法使DataTables正常工作。 這是在Visual Studio 2017 for Mac中。 我正在嘗試獲取一個分頁表,該表響應瀏覽器的調整大小,具有列排序,搜索功能,首頁,下一頁等外觀漂亮的按鈕,頁面大小選擇器位於左上方,搜索窗口位於右上方。 我不斷得到不同的組合,當它看起來正確時,沒有列排序按鈕等。這是_Layout.cshtml文件中的內容:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - Maestro</title>
    <environment include="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
        <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
    </environment>
</head>
<body>
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a asp-area="" asp-controller="LogFileViewer" asp-action="SelectFile" class="navbar-brand">Maestro</a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a asp-area="" asp-controller="LogFileViewer" asp-action="SelectFile">LogFiles</a></li>
                    <li><a asp-area="" asp-controller="Home" asp-action="About">About</a></li>
                    <li><a asp-area="" asp-controller="Home" asp-action="Contact">Contact</a></li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; 2018 - Maestro</p>
        </footer>
    </div>
    <environment include="Development">
        <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"></script>
    </environment>
    <environment exclude="Development">
        <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"
                asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"
                integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT"></script>
        <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                crossorigin="anonymous"
                integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"></script>
        <script src="~/js/site.min.js" asp-append-version="true"></script>
    </environment>
    @RenderSection("Scripts", required: false)
</body>
</html>

在我的ViewFile.cshtml的頂部:

@{
    ViewData["Title"] = "View";
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"></script>
}

該表定義為:

  <table id="table_id" class="table table-condensed table-striped table-hover" width="100%" cellspacing="0">

表格下方是:

<script>$(document).ready(function ()
    {
    $('#table_id').dataTable( {
                "pagingType": "full_numbers",
                "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                "scrollY"  : "400px",
                "paging": true,
                "ordering": true,
                "info": true,
                "searching": true,
                "processing": true, // for show progress bar
                "serverSide": false, // for process server side
                "filter": true, // this is for disable filter (search box)
                "orderMulti": false, // for disable multiple column at once
                "columnDefs":
                [{
                    "targets": [0],
                    "visible": false,
                    "searchable": false
                }],
                 "columns": [
                    { "data": "DateTime", "name": "DateTime", "autoWidth": true },
                    { "data": "Msecs", "name": "Msecs", "autoWidth": true },
                    { "data": "Thread", "name": "Thread", "autoWidth": true },
                    { "data": "Level", "name": "Level", "autoWidth": true },
                    { "data": "Logger", "name": "Logger", "autoWidth": true },
                    { "data": "Host", "name": "Host", "autoWidth": true },
                    { "data": "MsgType", "name": "MsgType", "autoWidth": true },
                    { "data": "Message", "name": "Message", "autoWidth": true }
                ]

            });
        });</script>

> Is there some interaction between the js and css files in the
> _Layout.cshtml and the ones at the top of the ViewFile.cshtml?
> 
> What would be THE set of js and css files to include to get what I
> want?  I can't find images of what a set does.

在ViewFile.cshtml中的@section腳本{}中聲明您的數據表JavaScript代碼

@section scripts {
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
}

並將其他JavaScript代碼(用於數據表初始化)放在部分中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM