欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Asp.Net MVC 使用DataTable

程序员文章站 2022-06-11 22:31:32
...

Asp.Net MVC 使用DataTable

后台controller:

 public ActionResult query()
        {
            DataTable dt = stu.GetStudentList();
           
            return View(dt);
        }

前台 query.cshtml页面:

@using WebApplication3.Models
@using System.Data
@{
    ViewBag.Title = "query";
}
<script src="~/Scripts/addUser.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-1.10.2.js" type="text/javascript"></script>
    <table class="table">
        <caption>学生信息表</caption>
        <thead>
            <tr>

                @foreach (DataColumn col in Model.Columns)
                {
                    <th>@col.ColumnName]</th>
                }
            </tr>
        </thead>
        <tbody>
            @foreach (DataRow row in Model.Rows)
            {
                <tr>
                    <td >@row["stuNo"]</td>
                    <td >@row["name"]</td>
                    <td >@row["xibie"]</td>
                    <td >@row["sex"]</td>
                    <td >@row["age"]</td>
                    
                    <td><button type="button"  class="btn btn-primary edit"  value="@row["stuNo"]">编辑</button></td>
                    <td><button type="button"  class="btn btn-primary delete">删除</button></td>
                </tr>
            }
           
        </tbody>
    </table>