簡體   English   中英

使用通用類型&#39;PagedList.StaticPagedList <T> &#39;需要1個類型參數

[英]Using the generic type 'PagedList.StaticPagedList<T>' requires 1 type arguments

我正在使用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 col_UserDTO引用更改為List<ExpandedUserDTO> col_UserDTO

改用這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM