【发布时间】:2017-04-29 14:04:21
【问题描述】:
我正在尝试显示当前登录餐厅的预订,但出现以下错误。
传入字典的模型项的类型为“System.Collections.Generic.List1[RestaurantApplication.Models.Restaurant]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[RestaurantApplication.Models.RestaurantReservationEvent]”。
这是我的控制器
public ActionResult RestaurantReservationsPartialView()
{
string currentUserId = User.Identity.GetUserId();
var restaurantID = (from r in db.Restaurants
where r.OwnerId == currentUserId
select r).ToList();
ViewBag.RestaurantId = restaurantID;
return PartialView("_RestaurantReservations", restaurantID);
这是调用 PartialView 的视图
<div style="padding-top: 50px;">
@Html.Action("RestaurantReservationsPartialView")
</div>
这是部分视图,我想显示当前登录餐厅的预订列表。
@if (ViewBag.numReservations > 0 && ViewBag.ReservationStatus == "Pending")
{
<center><p id="pendingReservations">Here are your pending reservations</p>
</center>
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4 col-sm-4 col-xs-6">
<div class="panel panel-primary">
<div class="panel-heading">
<center><h1 class="panel-title">@Html.DisplayFor(modelItem => item.BookersName)</h1></center>
</div>
<div class="panel-body">
<h3 style="font-size: 16px">Booking Description: @Html.DisplayFor(modelItem => item.BookingDesc) <br />
Number of people: @Html.DisplayFor(modelItem => item.BookingNumberOfPeople)</h3>
<h3 style="font-size: 15px">
<h>Booking Date: @Html.DisplayFor(modelItem => item.BookingDate) at</h>
<h>@Html.DisplayFor(modelItem => item.BookingStartTime)</h>
</h3>
</div>
<div class="panel-footer">
<center>@Html.ActionLink("Accept", "AcceptReservation", new { id = item.RestaurantReservationEventID }, new { @class = "btn btn-success btn-xs" }) @Html.ActionLink("Decline", "DeclineReservation", new { id = item.RestaurantReservationEventID }, new { @class = "btn btn-danger btn-xs" })</center>
</div>
</div>
</div>
}
}
【问题讨论】:
-
您需要将
RestaurantReservationEvent的集合传递给局部视图。这也不是部分视图调用。它正在执行一个动作方法 -
谢谢@Shyju,但我只想要一个 id (RestaurantID) 怎么办
-
你有一个叫
RestaurantReservationsPartialView的动作方法吗?看起来怎么样? -
是的,它在我帖子的顶部,控制器
-
我没看到。确保在问题中发布代码的相关部分。
标签: asp.net-mvc entity-framework linq