首先我是一个完全的MVC新手。如果某个布尔字段为true,我怎样才能在事件表中从数据库中显示数据于局部视图中。
这是我的局部视图:
@model IEnumerable<TheBigEvent.Models.RecommendedEvents>
<table>
<tr>
<td>
@Html.DisplayNameFor(model => model.Event_Name)
</td>
<td>
@Html.DisplayNameFor(model => model.Event_Date)
</td>
</tr>
<tr>
@foreach (var item in Model) {
<td>
@Html.DisplayFor(modelItem => item.Event_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Event_Date)
</td>
}
</tr>
</table>
这是我的控制器
public ActionResult _RecommendedEvents()
{
var recommendedevents = from Events in db.Database1
select Events;
recommendedevents = recommendedevents.Where(s => s.Recommended.Equals(true));
return PartialView("_RecommendEvents", recommendedevents);
}
显示局部视图的代码
@Html.Partial("_RecommmndedEvents")
这是我收到的错误信息:
![enter image description here](https://istack.dev59.com/vp2D7.webp)
public ActionResult _RecommendedEvents(RecommendedEvents model)
{
model = new RecommendedEvents();
var recommendedevents = from Events in db.Database1
select Events;
recommendedevents = recommendedevents.Where(s => s.Recommended.Equals(true));
return View(model);
}
model
变量,并且没有以任何方式更改它就返回了它。我怀疑这是不正确的。你是不是想要return View(recommendedevents);
? - Graham