asp.net mvc在局部视图中进行过滤和分页

时间:2014-09-29 07:43:04

标签: c# asp.net-mvc-partialview

我正在尝试使用PagedList.Mvc过滤结果列表进行分页。对于每个过滤结果使用部分视图绑定。但是我没有实现我的目标。如果有人帮助我,我非常感激

部分视图:

@using PagedList
@using PagedList.Mvc
@model IPagedList<item>

@foreach (var item in Model)
{
----
---
}

<div id="myPager">
    @Html.PagedListPager(
        Model,
        page => Url.Action(
            "Index",
            new
            {
                page = page
            }
        ),
        new PagedListRenderOptions
        {
            LinkToFirstPageFormat = "<<",
            LinkToPreviousPageFormat = "prev",
            LinkToNextPageFormat = "next",
            LinkToLastPageFormat = ">>",
        }
    )
</div>

查看:

 <section class="sub_work before_rghtpart get_jobs">              
     @*Render Partial View*@
 </section>



<script>
    $(document).ready(function () {
        function getJob() {
            $.post('@Url.Content("~/findwork/LoadAllJobs/")', function (data) {
                $('.get_jobs').html("");
                $('.get_jobs').html(data);
            });
        }
        getJob();
    });
</script>

$('.btnsearch').click(function (e) {
     e.preventDefault();
     if ($('#searchKey').val() != '' && $('#searchKey').val() != 'Search my previous job') {
         var scKey = $('#searchKey').val();
         $.post('@Url.Content("~/findwork/SearchJobsBySearchKey/")', { schKey: scKey }, function (data) {
             $('.get_jobs').html("");
             $('.get_jobs').html(data);
        });
    }
    else {
        alert('please enter searchkey');
    }
});

控制器:

 public ActionResult Index()
 {
     try
     {
         jobCategoryList = LoadCategory();
         jobListVM.jobCategory = jobCategoryList;
         return View(jobListVM);
     }
     catch { throw; }
 }

 public ActionResult LoadAllJobs(int page = 1)
 {
     JobSearch jobSearch = new JobSearch();
     jobSearchList = jobSearch.GetAllJobs();

     ViewBag.TotalResult = jobSearchList.Count;
     return PartialView("_JobsList", jobSearchList.ToPagedList(page, 5));
 }
 public ActionResult SearchJobsBySearchKey(string schKey)
 {
     JobSearch jobSearch = new JobSearch();
     jobSearchList = jobSearch.GetAllJobs();
     jobSearchList = jobSearchList.Where(k => k.JobName.ToLower().Contains(schKey.ToLower()) || k.JobDescription.ToLower().Contains(schKey.ToLower()) || k.JobSkill.All(x => x.SkillName.ToLower().Contains(schKey.ToLower()))).ToList();


     ViewBag.TotalResult = jobSearchList.Count;
     return PartialView("_JobsList", jobSearchList);
 }

抱歉我的语言不好。

0 个答案:

没有答案