我在View页面上声明并序列化了数据
@model IEnumerable<MVCvs2012.Models.Employees>
@{
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var employees = @serializer.Serialize(ViewData["Employees"]);
}
运行浏览器时的结果:
[{"FirstName":"Nancy","LastName":"Davolio","Title":"Sales Representative"}]
我想使用jquery将这些数据呈现到这样的表中:
<table id="employee">
<tr>
<td>Nancy</td>
<td>Davolio</td>
<td>Sales Representative</td>
</tr>
...
</table>
答案 0 :(得分:1)
使用jQuery.each构建您的表格。
的内容$var table = '<table>';
$.each(yourJson, function( index, value ) {
$table += '<tr><td>' + value.FirstName + '</td><td>' + ...
});
$table += '</table>';