【发布时间】:2014-09-02 00:54:46
【问题描述】:
我有问题。 我有我的控制器“DashboardNB2Controller”,我的视图“index.cshtml”,我想在我的“index.cshtml”中集成一个名为“_PartialView.cshtml”的局部视图。两个视图都在同一个文件夹中。在我的控制器中,我的局部视图中有数据库操作的“ActionResult _PartialView”。
但如果我将部分视图集成到索引视图中,则操作结果“_PartialView”不起作用。我没有得到任何结果。我的数据库的查询是正确的。我检查了这个。
这是我的代码
-
我的控制器带有部分视图的 ActionResult
public ActionResult _PartialView() { var lastMessages= (from t in db.view_tbl_message orderby t.Date descending select t).Take(10); ViewModelDashboard model = new ViewModelDashboard(); model.view_tbl_message = lastMessages.ToList(); return PartialView("_PartialView", model); }
我的 index.cshtml
@model AisWebController.Areas.Statistics.Models.ViewModelDashboard
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
@{Html.Action("_PartialView", "DashboardNB2");}
<br />
还有我的 _PartialView.cshtml
@model WebApplication.Areas.Stats.Models.ViewModelDashboard
<table class="table table-bordered">
<tr>
<th>
Date
</th>
<th>
User
</th>
<th>
Message
</th>
</tr>
@foreach (var item in Model.view_tbl_message)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Date
</td>
<td>
@Html.DisplayFor(modelItem => item.User)
</td>
<td>
@Html.DisplayFor(modelItem => item.Message)
</td>
</tr>
}
</table>
如果有人可以提供帮助,那就太棒了!
【问题讨论】:
标签: asp.net-mvc c#-4.0 razor model-view-controller partial-views