【发布时间】:2014-10-02 11:00:28
【问题描述】:
我正在使用 asp.net MVC 5。
我有一个 _layout 文件如下:
<!DOCTYPE html>
<html lang="en">
<head>
@Html.Partial("_Head")
@RenderSection("styles", required: false)
</head>
<body>
@RenderBody()
@RenderSection("scripts", required: false)
</body>
</html>
然后我有我的主要观点:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
Title = "mainView"
}
<div class="partialcontents" data-url="/user/UserList"></div>
$(document).ready(function (e) {
$(".partialcontents").each(
function (index, item) {
var url = $(item).data("url");
if (url && url.length > 0) {
$(item).load(url, function () { $(this).css("background-image", "none"); });
}
}
);
});
这是我的部分观点:
@{
}
<p> Partial View</p>
@section scripts
{
@Scripts.Render("~/bundles/script/datatable")
}
My controller that renders the partial view:
[Authorize]
public ActionResult UserList(UsersViewModel model, string sortOrder, string currentFilter, string searchString, int? page)
{
.... removed for simplicity
return PartialView("_UserList", new UsersViewModel()
{
Users = users.ToPagedList(pageNumber, pageSize)
});
}
所以现在我的问题是部分视图中的部分没有在主布局文件中呈现。我明白我为什么认为...
这是因为我在另一个控制器中渲染它。然后传下去。
但是我怎样才能做到这一点呢?
【问题讨论】:
-
根据上面的详细信息,我没有在布局页面中找到除 _Head @Html.Partial("_Head") 之外的任何局部视图。我没有找到任何使用“_UserList”部分视图的视图。
标签: c# asp.net-mvc asp.net-mvc-5 asp.net-mvc-partialview