2011-04-30 36 views
0

上thisnd smeting奇怪的是发生的购物部分工作。当我去填充我lixt我得到的错误:误差列表<T>说,“使用通用型‘System.Collections.Generic.List’需要1个类型参数”

Using the generic type 'System.Collections.Generic.List' requires 1 type arguments

我这样做对其他几类,但没有给这个错误。下面是导致错误的类:

StoreItem.cs

public class StoreItemViewModel 
{ 
    public StoreItemViewModel() 
    { 
     this.StoreItems = GetStoreItemList(null); 
    } 

    private SelectList GetStoreItemList(string selectedValue) 
    { 
     List<StoreItems> list = new List<StoreItems>(); 
     IRepository<GodsCreationTaxidermy.Data.StoreItem> storeItems = ObjectFactory.GetInstance<IRepository<StoreItem>>(); 

     foreach (StoreItem item in storeItems.GetAll()) 
     { 
      List.Add(new StoreItems <= error on this line 
      { 
       Key = item.Key, 
       CategoryKey = item.CategoryKey, 
       ItemName = item.ItemName, 
       ItemDescription = item.ItemDescription, 
       ItemPriced = item.ItemPrice, 
       DatePosted = item.DatePosted, 
      }); 
     } 

     return new SelectList(list, "StoreItemID", "StoreItemName", selectedValue); 
    } 

    [UIHint("StoreItems")] 
    public SelectList StoreItems { get; private set; } 

    [Required(ErrorMessage = "Store Item is required")] 
    public string StoreItem { get; set; } 
} 

我可以给其它类做这个确切的事情(也许一个新的集合F眼睛可以在这里),这里是其中的一个:

AnimalList.cs

public class AnimalsList 
{ 
    public AnimalsList() 
    { 
     this.Animals = GetanimalList(null); 
    } 

    private SelectList GetanimalList(string selectedValue) 
    { 

     List<Animal> list = new List<Animal>(); 
     IRepository<AnimalList> animals = ObjectFactory.GetInstance<IRepository<AnimalList>>(); 

     foreach (AnimalList animal in animals.GetAll()) 
     { 
      list.Add(new Animal 
      { 
       AnimalId = animal.animal_id, 
       AnimalName = animal.animal_name, 
       IsBird = Convert.ToBoolean(animal.is_bird), 
       MountType = animal.mount_type 
      }); 
     } 

     return new SelectList(list, "AnimalId", "AnimalName", selectedValue); 
    } 

    [UIHint("Animal")] 
    public SelectList Animals { get; private set; } 

    [Required(ErrorMessage = "Animal is required")] 
    public string Animal { get; set; } 
} 

有人能告诉我笏我做这里错了。我在过去几天里看到了很多很晦涩的错误(大部分是我解决的),但其他人我不得不寻求帮助。如果你需要更多代码,那么请让我知道:)

回答

2

列表是大写,所以你引用的是Class而不是实例“list”。

你应该考虑改变变量名有用的东西,少模糊或容易出错,所以你可以捕捉这些速度更快,或阻止他们完全。

0

在代码中你会看到List.Add,这不起作用。一旦我把它做成小写,一切都很好。

相关问题