上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; }
}
有人能告訴我笏我做這裏錯了。我在過去幾天裏看到了很多很晦澀的錯誤(大部分是我解決的),但其他人我不得不尋求幫助。如果你需要更多代碼,那麼請讓我知道:)