简体   繁体   English

使用通用类型&#39;PagedList.StaticPagedList <T> &#39;需要1个类型参数

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

I am working on user roles using Asp.net MVC. 我正在使用Asp.net MVC处理用户角色。 I am stuck while working on Admin section. 我在“管理”部分上工作时陷入困境。 I have mentioned one question above and the second question is similar which is Using the generic type 'System.Collections.Generic.List' requires 1 type arguments 我在上面提到了一个问题,第二个问题是类似的,即使用通用类型'System.Collections.Generic.List'需要1个类型参数

Here is my code. 这是我的代码。

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 is generic. StaticPagedList是通用的。 You need to supply the type of collection(for col_UserDTO), in your case List : 您需要提供集合的类型(对于col_UserDTO),在您的情况下为List

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

See http://www.programering.com/a/MTN2gDNwATM.html 请参阅http://www.programering.com/a/MTN2gDNwATM.html

You may need to change List col_UserDTO references to List<ExpandedUserDTO> col_UserDTO 您可能需要将List col_UserDTO引用更改为List<ExpandedUserDTO> col_UserDTO

Use this instead 改用这个

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用泛型类型'System.Collections.Generic.List <T>'需要1个类型参数 - Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments 使用通用类型&#39;System.Collections.Generic.List <T> &#39;在IRepository中需要1个类型参数 - Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments in IRepository 使用通用类型&#39;RoleManager <TRole, TKey> &#39;需要2个类型参数 - Using the generic type 'RoleManager<TRole, TKey>' requires 2 type arguments ASP.NET MVC - Model 传递的项目是 Generic.List 但需要类型 PagedList - ASP.NET MVC - Model Item passed is Generic.List but requires type PagedList 错误:无法将类型为“System.Collections.Generic.List”的对象强制转换为“X.PagedList.IPagedList” - ERROR: Unable to cast object of type 'System.Collections.Generic.List' to type 'X.PagedList.IPagedList' 传递到字典中的模型项是视图模型类型,但需要通用IEnum - The model item passed into the dictionary is of type view model but requires generic IEnum 字典需要System.Collections.Generic.List类型的模型项 - Dictionary requires a model item of type System.Collections.Generic.List 需要类型为&#39;System.Collections.Generic.IEnumerable`1的模型项 - Requires a model item of type 'System.Collections.Generic.IEnumerable`1 传递到字典中的模型项的类型为&#39;System.Collections.Generic.List,但是此字典需要类型为的模型项 - model item passed into the dictionary is of type 'System.Collections.Generic.List, but this dictionary requires a model item of type 传递到字典中的模型项属于类型,但此字典需要类型为“System.Collections.Generic.IEnumerable”的模型项 - The model item passed into the dictionary is of type, but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM