データベースにこのテーブルがあります:
ブラウザーに値 (ModuleID
および) を表として表示しようとしています。DateEntered
ビューに値を渡すためにビューバッグを使用していますが、現在は 1 行しか取得していないため、これは適切な方法ではありません。私が今していることは、
public ActionResult Index()
{
var modules = (from entries in _db.Modules
orderby entries.DateEntered
select entries);
ViewBag.entries = modules.ToList();
return View();
}
上の図のテーブルからすべての行を取得してビューに渡すにはどうすればよいですか? 私の見解では、私は現在持っています:
@using BootstrapSupport
@model Sorama.DataModel.SIS.ModuleStock.Module
@{
ViewBag.Title = "Index";
Layout = "~/Views/shared/_BootstrapLayout.basic.cshtml";
}
<table class="table table-striped">
<caption></caption>
<thead>
<tr>
<th>
Module ID
</th>
<th>
Date Entered
</th>
</tr>
</thead>
<tr>
@foreach (var entry in ViewBag.entries)
{
<td>@entry.ModuleId</td>
<td>@entry.DateEntered</td>
}
<td>
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Action
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>@Html.ActionLink("Details", "Details")</li>
@if (Request.IsAuthenticated && HttpContext.Current.User.IsInRole("Admin"))
{
<li class="divider"></li>
<li>@Html.ActionLink("Edit", "Edit")</li>
<li>@Html.ActionLink("Delete", "Delete")</li>
}
</ul>
</div>
</td>
</tr>
</table>
ModuleID
これは、 ( and )だけでなく、行全体の値を示しています。DateEntered
これはブラウザで取得したものです。
要約すると、テーブルからすべての行を取得したいが、特定の列のみを取得したい。これは現在の状況では起こっていません。提案?