用JSON数据向已定义列的表格添加数据行
其实添加方式和在MVC中动态读取JSON数据创建表格一样,只不过一个是完整表格添加,一个是从表格中间添加.不详细说明了.
<div> <table class="table"> <tr> <td class="col-md-1"> @Html.DisplayNameFor( model => model.UserID ) </td> <td class="col-md-2"> @Html.DisplayNameFor( model => model.UserName ) </td> <td class="col-md-2"> @Html.DisplayNameFor( model => model.DisplayName ) </td> <td class="col-md-3"> @Html.DisplayNameFor( model => model.Email ) </td> <td class="col-md-1"> @Html.DisplayNameFor( model => model.Longger_RoleRoleID ) </td> </tr> <tbody id="userTable"> </tbody> </table> </div> <script type="text/javascript"> $.getJSON("@Url.Action("GetAllUsers","User")", function (json) { var htmls = ['<hr />'] for (var i = 0; i < json.length; i++) { htmls.push('<tr>'); for (var k in json[i]) htmls.push('<td>' + json[i][k] + '</td>'); htmls.push('</tr>'); } $('#userTable').html(htmls.join('')); }); </script>