不包含“ ToPagedList”的定义

时间:2018-09-25 10:45:33

标签: c# .net pagedlist

我正在尝试使用 PagedList PagedList.Mvc

对我的代码实现分页

我面临的问题是我遇到了错误

  

“ Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”发生在   System.Core.dll,但未在用户代码中处理

     

其他信息:“ System.Collections.Generic.List”   不包含“ ToPagedList”的定义

以下是我的 PJController.cs 代码:

public ActionResult Index(SearchPostedJob objSearchPostedJob, int? page)
    {
        Result res = null;
        try
        {
            objSearchPostedJob.page = (objSearchPostedJob.page == null ? 1 : objSearchPostedJob.page);
            ViewBag.SearchPostedJob = objSearchPostedJob;
            res = objPostedJobDAL.GetPostedJobs(ApplicationSession.CurrentUser.RecruiterId);

            if (res.Status)
            {
                page = 1;
                ViewBag.Message = "";
            }
            else
            {
                ViewBag.Message = Common.GetMessage(res.MessageId, "[Master]", "Keyword");
            }
        }
        catch (Exception ex)
        {
            Common.WriteLog(ex);
            throw ex;
        }

        var result = res.Results;
        int pageSize = 3;
        int pageNumber = (page ?? 1);
        return View(result.ToPagedList(pageNumber, pageSize));
    }

以下是 Index.cshtml 的代码:

@model PagedList.IPagedList<NOS.SC.PJ>
@using PagedList.Mvc;
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="postjob-form">

@using (Html.BeginForm("Index", "PostedJob", FormMethod.Get))
{
    <div class="j_search" style="margin-left:3%;">
        <input class="form-control" name="SearchKeyword" id="SearchKeyword" placeholder="Search Keyword" />
    </div>
    <div class="j_search">
        <input id="pinput1" name="JobLocation" class="form-control" type="text" value="@ViewBag.SearchPostedJob.JobLocation" placeholder="Enter a location">
        <input id="Latitude" name="Latitude" type="hidden" value="@ViewBag.SearchPostedJob.Latitude">
        <input id="Longitude" name="Longitude" type="hidden" value="@ViewBag.SearchPostedJob.Longitude">
    </div>
    <div class="j_search">
        <select class="form-control" name="Experience" id="Experience">
            <option value="" selected>Select Experience</option>
            @for (int i = 1; i <= 10; i++)
            {
                <option value="@i" @(ViewBag.SearchPostedJob.Experience == i ? "selected" : "")>@i</option>
            }
        </select>
    </div>
    <div class="j_search">
        <select class="form-control" name="Salary" id="Salary">
            <option value="" selected>Select Salary</option>
            @for (int i = 1; i <= 10; i++)
            {
                <option value="@i" @(ViewBag.SearchPostedJob.Salary == i ? "selected" : "")>@i</option>
            }
        </select>
    </div>

    <div class="add-btn"><a class="btn btn-primary" href="~/PostedJob/Save?returnUrl=/PostedJob/Index">Add New Opening</a></div>

}
</div>
<div>

<table class="table" id="myTable">
    <tr>

        <th>
            @Html.DisplayNameFor(model => model[0].JobTitle)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].JobLocation)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].NumberOfPositions)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].ValidFrom)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].ValidTo)<br />
        </th>

        <th>
            @Html.DisplayNameFor(model => model[0].JobReference)
        </th>

        <th>
            @Html.DisplayNameFor(model => model[0].Status)
        </th>
        <th>
            Application
        </th>
        <th>
            CloneJob
        </th>

        @foreach (var item in Model)
        {
        <tr>

            <td>
                @Html.DisplayFor(modelItem => item.JobTitle)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.JobLocation)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.NumberOfPositions)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.ValidFrom)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ValidTo)<br />

                @* @Html.ActionLink("Delete Resume", "DeleteResume", new { ResumeId = Model.ResumeId, returnUrl = "/Nurse/ProfileView" }, new { @class = "btnViewJobDetails" })*@
                @if (!item.IsExtendJob)
                {


                    @Html.ActionLink("ExtendJob", "ExtendJob", new { PostedJobId = item.PostedJobId, IsExtendJob = item.IsExtendJob, returnUrl = "/PostedJob/Index" }, new { @class = "btnViewJobDetails" })
                }
                else
                {
                    <span class="pull-right" style="font-weight:bold; color:red;">JobExtended</span>
                }

            </td>
            <td>
                @Html.DisplayFor(modelItem => item.JobReference)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Status)
            </td>
            <td>
                @Html.ActionLink("Applied(" + item.AppliedCnt + ")", "JobView", new { PostedJobId = item.PostedJobId, returnUrl = "/PostedJob/Index" }, new { @class = "btnViewJobDetails" })

            </td>
            <td>
                @Html.ActionLink("JobClone", "CloneJob", new { PostedJobId = item.PostedJobId, returnUrl = "/PostedJob/Index" }, new { @class = "btnViewJobDetails" })
            </td>

        </tr>
        }

    </table>

    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

    @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
</div>


@section Scripts
 {
    @Scripts.Render("~/bundles/jqueryui")
    @Styles.Render("~/Content/themes/base/css")
    @Scripts.Render("~/bundles/jqueryval")
    <script>
        function initMap() {
            var input = document.getElementById('pinput1');
            var autocomplete = new google.maps.places.Autocomplete(input);
            autocomplete.addListener('place_changed', function () {
                var place = autocomplete.getPlace();
                console.log(JSON.stringify(place));
                if (!place.geometry) {
                    window.alert("Autocomplete's returned place contains no geometry");
                    return;
                }
                var latlong = JSON.parse(JSON.stringify(place.geometry.location));
                document.getElementById('Latitude').value = latlong.lat;
                document.getElementById('Longitude').value = latlong.lng;
            });
        }
        initMap();
    </script>

    <script>
        $(document).ready(function () {
            $("#SearchKeyword").on("keyup", function () {
                var value = $(this).val().toLowerCase();
                $("#myTable tr").filter(function () {
                    $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
                });
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $("#pinput1").on("keyup", function () {
                var value = $(this).val().toLowerCase();
                $("#myTable tr").filter(function () {
                    $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
                });
            });
        });
    </script>
}

1 个答案:

答案 0 :(得分:0)

尝试使用此:

public ActionResult Index(FilterPostedJob objFilterPostedJob, int? page)
    {
        Result res = null;
        try
        {
            objFilterPostedJob.CreatedBy = ApplicationSession.CurrentUser.RecruiterId;

            objFilterPostedJob.page = (objFilterPostedJob.page == null ? 1 : objFilterPostedJob.page);
            ViewBag.SearchPostedJob = objFilterPostedJob;
            res = objPostedJobDAL.GetPostedJobs(objFilterPostedJob);

            int pageSize = 10;
        int pageNumber = (page ?? 1);
        return View(((List<PostedJob>)res.Results).ToPagedList(pageNumber, pageSize));

        }
        catch (Exception ex)
        {
            Common.WriteLog(ex);
            throw ex;
        }          
    }

使用ToPagedList是一个附加的优势,因为您需要做的就是传递PageNumber和PageSize