MVC 项目 在前台使用DataTable

1:后台控制器代码

//CreateTestOutputDataHeader生成一个测试DataTable
public ActionResult UseDataTable()
        {
            DataTable dt = CreateTestOutputDataHeader();
            return View(dt);
        }

2:前台使用方法:

@using System.Data;
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>UseDataTable</title>
</head>
<body>
    <div>
        <table border="1" cellpadding="0" cellspacing="0">
            @foreach (System.Data.DataRow item in Model.Rows)
            {
                <tr>
                    <td>
                        @item["name"]
                    </td>
                </tr>
            }
        </table>
        
    </div>
</body>
</html>
原文地址:https://www.cnblogs.com/volts0302/p/5165941.html