我正在尝试选择已登录用户的餐馆ID并将其传递给部分视图以显示该用户的预订列表。
我目前有
@model IEnumerable<RestaurantApplication.Models.Restaurant>
@{
ViewBag.Title = "Home";
}
@if (ViewBag.IsRestaurant == true)
{
<h2>You are logged in a restaurant user</h2>
<p>
@Html.ActionLink("Create New Restaurant", "CreateRestaurant", null, new {
@class = "btn btn-success" })
</p>
@Html.Action("RestaurantReservationsPartialView", new { id = 1 })
这里我想用当前餐馆的id替换id = 1
我的代码显示用户餐馆列表
if (Model.Count() != 0)
{
<h1>Your Current Restaurants</h1>
<table id="restaurantOwnerTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Rating</th>
<th>Restaurant Name</th>
<th>County</th>
<th>Type</th>
<th>Options</th>
</tr>
</thead>
<tbody>
@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("View Reservations", "ViewReservations", new { id = item.RestaurantID }) |
@Html.ActionLink("View ReservationsToday", "ViewReservationsToday", new { id = item.RestaurantID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.RestaurantID })
</td>
</tr>
}
</tbody>
</table>
}
else
{
@Html.Label("You do not have any Restaurants , consider making one?")
}
}
答案 0 :(得分:0)
您应该在循环所有餐馆的循环中调用子操作,并在循环迭代中使用每个项的RestaurnatID属性。
例如,
@model IEnumerable<RestaurantApplication.Models.Restaurant>
@foreach (var item in Model)
{
<tr>
<td>
@Html.Action("RestaurantReservationsPartialView", new { id = item.RestaurantID})
</td>
</tr>
}