0
コントローラー内の情報の検索を変更したくないので、コントローラーではなくビュー内にwhere節を追加することは可能ですか?私は現在、レストランのリストを取得していますが、ログインしたユーザーの電子メールがレストランの電子メールと同じであるレストランのみを表示したいとします。ビュー内でリストを返すときにwhere節を追加する方法
<div class="col-xs-12">
<table class="table table-condensed table-striped">
<tr>
<th>
@Html.DisplayNameFor(model => model.Rating)
</th>
<th>
@Html.DisplayNameFor(model => model.RestaurantName)
</th>
<th>
@Html.DisplayNameFor(model => model.County)
</th>
<th>
@Html.DisplayNameFor(model => model.RestaurantType)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Rating)
</td>
<td>
@Html.DisplayFor(modelItem => item.RestaurantName)
</td>
<td>
@Html.DisplayFor(modelItem => item.County)
</td>
<td>
@Html.DisplayFor(modelItem => item.RestaurantType)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.RestaurantID }) |
@Html.ActionLink("Details", "Details", new { id = item.RestaurantID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.RestaurantID })
</td>
</tr>
}
</table>
</div>
最高の選択肢はおそらくビューモデルを作成することでしょう –
モデルのコードを共有できますか? – Usman
コントローラでこれを行うための適切な場所。ビューは、渡されたデータを表示する役割を担います。したがって、1)コントローラーで必要のないデータを取得せず、2)表示したくないコントローラーにデータを渡さないでください。 – mason