[英]How do I pass one ID from a view which has a Model Type of IEnumerable to aPartial View
我正在尝试选择已登录用户的餐厅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?")
}
}
您应该在循环所有餐厅的循环中调用子动作,并在循环迭代中使用每个项目的RestaurnatID属性。
例如,
@model IEnumerable<RestaurantApplication.Models.Restaurant>
@foreach (var item in Model)
{
<tr>
<td>
@Html.Action("RestaurantReservationsPartialView", new { id = item.RestaurantID})
</td>
</tr>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.