代码之家  ›  专栏  ›  技术社区  ›  user7560542

在视图中,是否有一种简单/自动的方法从列表中的所有数据中生成表?

  •  0
  • user7560542  · 技术社区  · 7 年前

    我有一个超过20列的列表,不想手动构建 <th> <td> . 是否有一种简单/自动的方法来告诉MVC生成一个包含某个列表中所有数据的基本表?

    1 回复  |  直到 7 年前
        1
  •  1
  •   ViRuSTriNiTy    7 年前

    如何使用jquery数据表?

    https://datatables.net/examples/data_sources/js_array.html

    然后这个视图看起来像这样

    @model  string[]
    
    <script>
        var dataSet = [
            [@string.Join("], ", Model.Select(o => o))] // convert model to array data, you could also use a serializer here
        ];
    
        $(document).ready(function () {
            $('#example').DataTable({
                data: dataSet,
                columns: [
                    { title: "My strings" }
                ]
            });
        });
    </script>
    
    <table id="example" class="display" width="100%"></table>