1

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.IEnumerable1[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

4 回答 4

2

不确定这是否可行,但您可以尝试将 EntityCollection 包装到 ViewModel 类中并将其传递给 View,如下所示:

public class GroupsViewModel()
{
    public GroupCollection Groups { get; set; }
    // other items in your view model could go here
}

然后将您的控制器方法转换为

public ActionResult Index()
{
    GroupCollection gc = new GroupCollection();
    gc.GetMulti(null);
    GroupsViewModel vm = new GroupsViewModel();
    vm.Groups = gc;
    return View(vm);
}

我喜欢这种方法,因为每个 ViewModel 本身就是一个对象。

于 2010-01-26T16:41:13.027 回答
0

您可以使用 AsEnumerable 扩展名,您的 ??????? 是或将您的 ViewUserControl(在标记中)的类型更改为 System.Collections.Generic.List 类型。基本上你需要纠正的是视图类型和传入的模型之间的不匹配。

于 2009-10-14T19:45:36.007 回答
0

我不确定您的确切错误,但我敢猜测正在发生两件事之一:

  • 您正在对 LLBLGen 对象进行某种无效/非法调用。如果是这种情况,请确保您设置正确/调用正确的方法/属性等。

  • 您传递给 veiw 的模型太长了,它无法处理。在这种情况下,一般来说,您应该创建一个轻量级的“视图模型”类,其中只包含您想要显示的数据,并首先从您的 LLBLGen 对象中填充它,然后将其传递给视图,这将能够轻松处理您的视图模型班级。

以下是一些参考资料:

于 2009-10-14T19:45:59.557 回答
0

根据 Yuriy 所说,看起来您的视图被强类型化为您的 groupentity 集合的“集合”,并且您正试图仅传递您的 groupentities 的集合。确保您的“集合”类型(IEnumerable、IList 等)与您在控制器中发送的集合类型以及集合中实际对象的类型相匹配。

视图:System.Collections.Generic.List1[glossary.EntityClasses.GroupEntity]

控制器:System.Collections.Generic.List1[glossary.EntityClasses.GroupEntity]

只是一个想法

于 2010-05-21T16:08:55.817 回答