ASP.NET MVC应用程序(模型)中的排序,筛选和分页

时间:2014-02-11 13:58:55

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

ASP.NET MVC 5应用程序中的排序,筛选和分页。

我的代码:

@model PagedList.IPagedList<PublicRelations.Models.Suggestion>
@using PagedList.Mvc;
...
...
...
    <table class="table table-hover table-striped table-responsive">
        <tr>
            <th>

                @Html.ActionLink(model => model.Name, "Index", new { sortOrder = ViewBag.NameSortParm })
            </th>
            <th>
    ...
    ...
    ...
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td>
    ...
    ...
    ...
    </table>
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
            @Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))

错误:

@Html.ActionLink(model => model.Name, "Index", new { sortOrder = ViewBag.NameSortParm })

错误:无法将lambda表达式转换为类型'string',因为它不是委托类型。 ????

2 个答案:

答案 0 :(得分:1)

确保已导入System.Linq命名空间

如果已经,请提供一些其他信息以了解确切的问题区域。

希望有所帮助。

答案 1 :(得分:0)

我使用此页面的代码进行排序和过滤等。 文本中的双向链接,用于手动输入。我根据标题链接标题标题确定。

Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application