私はMVC3 Webアプリケーションを作成しています。私のデータベースのデータで満たされているテーブルがありますが、私のシノプシスの最初の3行は、すべての10行の代わりに。私はこれはHTMLヘルパーと関係があると思いますが、あなたの誰かが私が正しいコードを見つけるのを助けることができるかどうか疑問に思っていましたか? どんな助力も素晴らしいだろう!私のビューのHTMLヘルパーが必要ですが、何を使うべきかわからない
@model IEnumerable<TheatreGroup.Models.Show>
@{
ViewBag.Title = "Shows";
}
<h2>
Shows</h2>
<p>Below is a list of shows which will be avalible in the next couple of weeks</p>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm())
{
<p>
Find by name: @Html.TextBox("SearchString")
<input type="submit" value="Search" /></p>
}
<table>
<tr>
<th>
@Html.ActionLink("name", "Index", new { sortOrder = ViewBag.nameSortParm,})
</th>
<th>
@Html.ActionLink("writer", "Index", new { sortOrder = ViewBag.writerSortParm,})
</th>
<th>
@Html.ActionLink("synopsis", "Index", new { sortOrder = ViewBag.synopsisSortParm, })
</th>
<th>
</th>
</tr>
@foreach (var item in Model){
<tr>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.writer)
</td>
<td>
@Html.DisplayFor(modelItem => item.synopsis)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.showid }) |
@Html.ActionLink("Details", "Details", new { id = item.showid }) |
@Html.ActionLink("Delete", "Delete", new { id = item.showid })
</td>
</tr>
}
</table>
+1には、ビューモデルに実際にビューに表示される情報のみが含まれていることに注意してください。これらのソリューション2は、コントローラーに必要なものだけを投入する方が優れています。その後、元のループをきれいにすることができます。私の解決策はすばやく修正されました! – Dangerous