仅分页部分视图

时间:2018-04-27 15:41:42

标签: asp.net-mvc razor

我有一个调用两个部分视图的视图。

_partialView是一个PagedList,_viewHeader有单选按钮可以选择各种过滤器。我需要能够在不重新加载_viewHeader的情况下翻阅_partialView。

这很有效,但是当我点击寻呼机按钮并且单选按钮被设置为默认值时,会重新加载_viewHeader视图。

@Html.PagedListPager(Model, page => Url.Action("Index", new { currentFilter = @ViewBag.CurrentFilter, page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() {InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "partial" }))

如果我在单击页面按钮时执行此操作,只需加载_partialView而不使用标题和布局(否则它可以正常工作)

 @Html.PagedListPager(Model, page => Url.Action("_partialView", new { currentFilter = @ViewBag.CurrentFilter, page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() {InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "partial" }))

显然,我做错了什么,有什么建议吗?

这是我的Index.cshtml视图。

@model PagedList.IPagedList<MyProject.Models.Kaizen>
@using PagedList;
@using PagedList.Mvc;


@*<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />*@

@{
    ViewBag.Title = "Home Page";
    ViewBag.AssignedTo = "";
}


@Html.Partial("_viewHeader")
<div id="partial">
   @Html.Action("_partialView", "Home")
</div>

1 个答案:

答案 0 :(得分:1)

对于任何感兴趣的人,我设法弄清楚如何使用JQuery来做到这一点。

//Page button clicked
        $(function(){
            $('#partial').on('click', 'a', function () {
                //alert('Click Detected');
                var url = $(this).attr('href');
                //alert(url);
                $('#partial').load(url);
                return false;
            })
        })

这会分页_partialView而不会影响_ViewHeader。