使用泛型类型"PagedList.StaticPagedList<T>"需要 1 个类型参数



我正在使用 Asp.net MVC处理用户角色。我在管理部分工作时被困住了。我在上面提到了一个问题,第二个问题类似,即使用泛型类型"System.Collections.Generic.List"需要 1 个类型参数

这是我的代码。

public ActionResult Index(string searchStringUserNameOrEmail, string currentFilter, int? page)
        {
            try
            {
                int intPage = 1;
                int intPageSize = 5;
                int intTotalPageCount = 0;
                if (searchStringUserNameOrEmail != null)
                {
                    intPage = 1;
                }
                else
                {
                    if (currentFilter != null)
                    {
                        searchStringUserNameOrEmail = currentFilter;
                        intPage = page ?? 1;
                    }
                    else
                    {
                        searchStringUserNameOrEmail = "";
                        intPage = page ?? 1;
                    }
                }
                ViewBag.CurrentFilter = searchStringUserNameOrEmail;
                List col_UserDTO = new List();
                int intSkip = (intPage - 1) * intPageSize;
                intTotalPageCount = UserManager.Users
                    .Where(x => x.UserName.Contains(searchStringUserNameOrEmail))
                    .Count();
                var result = UserManager.Users
                    .Where(x => x.UserName.Contains(searchStringUserNameOrEmail))
                    .OrderBy(x => x.UserName)
                    .Skip(intSkip)
                    .Take(intPageSize)
                    .ToList();
                foreach (var item in result)
                {
                    ExpandedUserDTO objUserDTO = new ExpandedUserDTO();
                    objUserDTO.UserName = item.UserName;
                    objUserDTO.Email = item.Email;
                    objUserDTO.LockoutEndDateUtc = item.LockoutEndDateUtc;
                    col_UserDTO.Add(objUserDTO);
                }
                // Set the number of pages
// Error appears here
                var _UserDTOAsIPagedList =
                    new StaticPagedList
                    (
                        col_UserDTO, intPage, intPageSize, intTotalPageCount
                        );
                return View(_UserDTOAsIPagedList);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, "Error: " + ex);
                List col_UserDTO = new List(); // Error appears here
                return View(col_UserDTO.ToPagedList(1, 25));
            }
        }
        #endregion

'

StaticPagedList是通用的。您需要提供集合类型(用于col_UserDTO),在您的情况下List

var _UserDTOAsIPagedList =
   new StaticPagedList<List<ExpandedUserDTO>>
      (
         col_UserDTO, intPage, intPageSize, intTotalPageCount
      );

见 http://www.programering.com/a/MTN2gDNwATM.html

您可能需要更改对List<ExpandedUserDTO> col_UserDTO List col_UserDTO引用

改用这个

var _UserDTOAsIPagedList =
   new StaticPagedList<ExpandedUserDTO>
      (
        col_UserDTO, intPage, intPageSize, intTotalPageCount
      );

相关内容

  • 没有找到相关文章

最新更新