List错误,显示“使用泛型类型“System.Collections.Generic.List”;需要 1 个类型参数”
从事购物部分的工作正在发生奇怪的事情。当我去填充我的 lixt 时,我收到错误:
使用泛型类型 '系统.集合.通用.列表' 需要 1 个类型参数
我已经在其他几个类上执行了此操作,但没有一个给出此错误。这是导致错误的类:
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; }
}
我可以向其他类展示执行此操作的其他类(也许这里可以使用一组新的眼睛),这是其中之一:
AnimalList.cs< /strong>
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; }
}
有人可以告诉我我在这里做错了什么吗?过去几天我看到了很多非常晦涩的错误(大多数我解决了),但其他错误我不得不寻求帮助。如果您需要更多代码,请告诉我:)
Working on the shopping part of thisnd smeting strange is happening. When I go to populate my lixt I get the error:
Using the generic type
'System.Collections.Generic.List'
requires 1 type arguments
I have done this on several other classes but none give this error. Here's the class causing the error:
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; }
}
I can show other classes that do this exact thing (maybe a new set f eyes can here) and here's one of them:
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; }
}
Can someone tell me wat I'm doing wrong here. I've seen a lot of very obscure errors the past few days (most I resolved) but others I had to ask for help.If you nee more code then ust let me know :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
列表是大写的,因此您引用的是类而不是实例“列表”。
您应该考虑将变量名称更改为有用的名称,并且不易模糊或不易出错,以便您可以更快地捕获这些变量,或完全阻止它们。
List is capitalized, so you're referencing the Class instead of the instance "list".
You should consider changing the variable name to something useful, and less vague or error prone so you can catch these faster, or prevent them entirely.
在代码中您会看到List.Add,这是行不通的。一旦我把它变成小写,一切都很好。
In the code you see List.Add, that's not going to work. Once I made it lower case all is well.