【问题标题】:Asp .Net Razor View table default sort order with BootstrapAsp .Net Razor View 表默认排序顺序与 Bootstrap
【发布时间】:2017-10-30 13:22:23
【问题描述】:

在 asp.net-core 控制器中,我按 BirthDate 属性对模型集合进行降序排序并将其返回到视图。虽然调试准备好的顺序得到尊重,但在显示视图表之前再次将排序方向更改为升序。

有没有办法通过在 Razor 视图中应用 Bootstrap 类来设置表格列的默认排序顺序从升序到降序?

<table id="table" class="table table-striped table-bordered" style="width:100%">
            <thead>
                <tr>
                    <th>Birth date</th>
                    <th>Name</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var person in Model)
                {
                    <tr>
                        <td>@person.BirthDate</td>
                        <td>@person.Name</td>

                    </tr>
                }
            </tbody>
        </table>

最简单的方法是什么?

【问题讨论】:

标签: twitter-bootstrap razor asp.net-core-mvc


【解决方案1】:

我将放置在单独 .js 文件中的脚本附加到视图页面。

$(document).ready(function() {
    $('#table').DataTable( {
        "order": [[ 0, "desc" ]]
    } );
} );

它有效;-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多