ReflectionIT filtering pagination working second page not working sorting not working in .net Core 2.1

旧城冷巷雨未停 提交于 2020-02-06 07:57:09

问题


I have I think correctly added reflectionIT framework but it still not works properly it actually renders the paging and filtering actually works but when I use the sorting it doesn't work, neither does the second third or any page besides the first one.

   public async Task<IActionResult> MenageUsers(string filter, int page = 1,string sortExpression = "UserName")
    {
            var qry = _userManager.Users.AsNoTracking().AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter))
            {
                qry = qry.Where(p => p.UserName.Contains(filter) || p.Name.Contains(filter) || p.SurName.Contains(filter)
                || p.Email.Contains(filter) );
            }

            var model = await PagingList.CreateAsync(
                                         qry, 10, page, sortExpression, "UserName");

            model.RouteValue = new RouteValueDictionary {
            { "filter", filter}
        };

            return View(model);

    }

The View

@model ReflectionIT.Mvc.Paging.PagingList<ProjectiWebFinal.Data.ApplicationUser>
@using ReflectionIT.Mvc.Paging
@addTagHelper *, ReflectionIT.Mvc.Paging

@{
    ViewData["Title"] = "Home Page";
    var user = (List<ApplicationUser>)ViewData["users"];
}
@using ProjectiWebFinal.Data

<a asp-action="CreateUser">CreateUser</a>
<form method="get" class="form-inline">
    <input name="filter" class="form-control" placeholder="filter"
           value="@Model.RouteValue["Filter"]" />
    <button type="submit" class="btn btn-info">
        <span class="glyphicon glyphicon-search" aria-hidden="true"></span> Search
    </button>
</form>

<nav aria-label="Products navigation example">
    <vc:pager paging-list="@Model" />
</nav>
<table id="" class="table">
    <thead>
        <tr>
            <th>
                @Html.SortableHeaderFor(model => model.Id, this.Model)
            </th>
            <th>
                @Html.SortableHeaderFor(model => model.UserName, this.Model)
            </th>
            <th>
                @Html.SortableHeaderFor(model => model.Email, this.Model)
            </th>
            <th>
                @Html.SortableHeaderFor(model => model.Name, this.Model)
            </th>
            <th>
                @Html.SortableHeaderFor(model => model.SurName, this.Model)
            </th>
            <th>
                @Html.SortableHeaderFor(model => model.Gender, this.Model)
            </th>
            <th>
                @Html.SortableHeaderFor(model => model.Coins, this.Model)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>

        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Id)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.UserName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Email)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.SurName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Gender)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Coins)
                </td>

                <td>
                    <a asp-controller="Admin" asp-action="EditUser" asp-route-id="@item.Id">EditUser</a>
                    <a asp-controller="Admin" asp-action="DeleteUser" asp-route-id="@item.Id">DeleteUser</a>
                </td>
            </tr>
        }
    </tbody>
</table>

I've also added the services.AddPaging() but first I did run the program without it because I forgot it then I added it and saved it but nothing changed.

Below the image of what's happening.

Update

for all the one's that are having this problem look at the url in my case it says Admin/Index?filter.... insted of Admin/ManageUsers this problem is caused because the PageList class by default has the Action = "Index" so change that to your action name one way is as i used var model = await PagingList.CreateAsync.... write model.Action="YourActionOrPageName"

来源:https://stackoverflow.com/questions/59850550/reflectionit-filtering-pagination-working-second-page-not-working-sorting-not-wo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!