我已决定尝试使用 ASP.NET MVC,但我想要替换的第一部分是模型。我使用 LLBL Pro 作为模型。
我有一个名为“组”的表,它是一个简单的查找表。我想获取表的结果并填充 MVC 中的列表。应该非常简单的事情......或者我认为......我已经尝试了各种各样的事情,因为我收到了错误,例如:
传递到字典中的模型项的类型为“System.Collections.Generic.List” 1[glossary.EntityClasses.GroupEntity]',但此字典需要类型为“System.Collections.Generic.IEnumerable
1[glossary.CollectionClasses.GroupCollection]”的模型项。
<代码>
private GroupCollection gc = new GroupCollection();
public ActionResult Index()
{
gc.GetMulti(null);
return View( gc.?????? );
}
这就是我想要做的,我尝试了很多变体,但我的目标只是获取数据并显示它。
I have settled on trying to use ASP.NET MVC but the first part I want to replace is the Model. I am using LLBL Pro for the model.
I have a table called "Groups" that is a simple look up table. I want to take thhe results of the table and populate a list in MVC. Something that should be very simple... or so I thought.... I've tried all kinds of things as I was getting errors like:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[glossary.EntityClasses.GroupEntity]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[glossary.CollectionClasses.GroupCollection]'.
private GroupCollection gc = new GroupCollection();
public ActionResult Index()
{
gc.GetMulti(null);
return View( gc.?????? );
}
This is all I am trying to do, I've tried lots of variations, but my goal is simply to take the data and display it.
发布评论
评论(4)
不确定这是否有效,但您可以尝试将 EntityCollection 包装到 ViewModel 类中并将其传递给 View,如下所示:
然后将控制器方法转换为
我喜欢这种方法,因为每个 ViewModel 本身就是一个对象。
Not sure if this would work, but you could try wrapping the EntityCollection into a ViewModel class and passing it to the View like so:
then convert your controller method to
I like this approach because each ViewModel is an object in-and-of itself.
您可以使用 AsEnumerable 扩展,您的 ??????将 ViewUserControl(在标记中)的类型更改为 System.Collections.Generic.List 类型。基本上,您需要纠正的是传入的视图类型和模型之间的不匹配。
You can use the AsEnumerable extension where your ????? are or change the type of your ViewUserControl(in the markup) to be of type System.Collections.Generic.List. Basically what you need to correct is the mismatch between the type of the View and the Model being passed in.
我不确定您的确切错误,但我大胆猜测发生了以下两件事之一:
您正在对 LLBLGen 对象进行某种无效/非法调用。如果是这种情况,请确保您正确设置/调用正确的方法/属性等。
您传递给 veiw 的模型太复杂,无法处理。在这种情况下,一般来说,您应该创建一个轻量级“视图模型”类,其中仅包含您想要显示的数据,并首先从 LLBLGen 对象填充它,然后将其传递给视图,这将是能够轻松处理您的视图模型类。
以下是一些参考:
I'm not sure about your exact error, but I'd venture a guess that one of two things are happenging:
You are making some sort of invalid / illegal call on your LLBLGen object. If this is the case make sure you are setting it up right / calling right method / property etc.
The model you are passing to the veiw is too hairy for it to deal with. In this case, and in general, you should create a light 'View Model' class with just the data you want displayed and populate it from your LLBLGen object first then pass it to the view, which will be able to easily handle your view model class.
Here are some references:
根据 Yuriy 的说法,您的视图似乎被强类型化为您的团体实体集合的“集合”,并且您试图仅传递您的团体实体的集合。确保您的“集合”类型(IEnumerable、IList 等)与您在控制器中发送的集合类型以及集合中实际对象的类型相匹配。
看法:
System.Collections.Generic.List1[glossary.EntityClasses.GroupEntity]
控制器:
System.Collections.Generic.List1[glossary.EntityClasses.GroupEntity]
只是一个想法
Stemming off what Yuriy said, it looks like your view is strongly typed to a "collection" of a collection of your groupentity, and you are trying to pass just the collection of your groupentities. Make sure your "collection" type (IEnumerable, IList, etc) matches what type of collection you are sending in your controller, along with the type of the actual object in the collection.
View:
System.Collections.Generic.List1[glossary.EntityClasses.GroupEntity]
Controller:
System.Collections.Generic.List1[glossary.EntityClasses.GroupEntity]
Just a thought