【发布时间】:2016-04-05 17:09:09
【问题描述】:
我正在使用 aws .net sdk 获取所有安全组并将它们显示在这样的表格中。
public object GetGroups()
{
var allSgRequest = new DescribeSecurityGroupsRequest();
var allSgResponse = client.DescribeSecurityGroups(allSgRequest);
var allSgGroups = allSgResponse.SecurityGroups;
return allSgGroups;
}
在我的控制器中,我调用该方法并将数据传递到我的视图中
public ActionResult SecurityGroups()
{
dynamic model = new ExpandoObject();
SecurityGroupModel sgm = new SecurityGroupModel();
var awsGroups = sgm.GetGroups();
model.group = awsGroups;
return View(model);
}
我在视图中设置的表使用 JQuery 的数据表插件,看起来像这样
@model dynamic
@{
ViewBag.Title = "SecurityGroups";
}
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery- 1.10.2.js"></script>
<link rel="stylesheet" type="text/css" href="/DataTables/datatables.css" />
<script type="text/javascript" src="/DataTables/datatables.js"></script>
<h2>SecurityGroups</h2>
<table id="table" class="table table-bordred table-striped">
<thead>
<tr>
<th>Group ID</th>
<th>Group Name</th>
<th>VPC ID</th>
</tr>
</thead>
<tbody>
@foreach (var group in Model.group)
{
<td>@group.GroupId</td>
<td>@group.GroupName</td>
<td>@group.VpcId</td>
}
</tbody>
<script type="text/javascript">
$('#table').DataTable();
</script>
但是,当我运行程序并进入我的视图时,数据显示很奇怪,并在一行上显示我的所有组,而不是在多行上正确显示。像这样
为什么我的数据只显示在一行上?
【问题讨论】:
标签: .net asp.net-mvc datatables