use*_*039 4 model-view-controller asp.net-mvc partial-views razor c#-4.0
我有个问题。我有我的控制器“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);
}
Run Code Online (Sandbox Code Playgroud)我的index.cshtml
@model AisWebController.Areas.Statistics.Models.ViewModelDashboard
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
@{Html.Action("_PartialView", "DashboardNB2");}
<br />
Run Code Online (Sandbox Code Playgroud)
还有我的 _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>
Run Code Online (Sandbox Code Playgroud)
如果有人可以提供帮助,那就太好了!
改变
@{Html.Action("_PartialView", "DashboardNB2");}
Run Code Online (Sandbox Code Playgroud)
到
@Html.Action("_PartialView", "DashboardNB2")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14703 次 |
| 最近记录: |