0
aws .net sdkを使用してすべてのセキュリティグループを取得し、そのようなテーブルに表示します。私のコントローラでMVCで複数の行ではなく1行にすべてのデータを表示するHTMLテーブル
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);
}
変数awsGroupsように私のビューにデータを渡す私の見解の用途に設定し、この
私のテーブルのようになりますjQueryのためのdatatablesプラグインはこのようになります。
@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>
は、しかし、私はプログラムを実行すると、データが表示さ不気味私のビューに移動して、複数の行に正しく表示する代わりに1行で私のグループのすべてを示しています。このようなもの
データが1行にしか表示されないのはなぜですか?
<tbody>
@foreach (var group in Model.group)
{
<tr>
<td>@group.GroupId</td>
<td>@group.GroupName</td>
<td>@group.VpcId</td>
</tr>
}
</tbody>
これは本当に単純な、うまく形成HTMLです:
ありがとうございます!私はそれが私が逃した簡単なことだったうれしいです。 – Pudding