views:

232

answers:

4
A: 

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.

Yuriy Faktorovich
A: 

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:

TJB
Out of curiosity, when have you seen the model being too nasty for the webforms viewengine?
Chad Ruppert
I don't remember where I read about it, i think its somewhere in the Nerd Dinner tutorial, but the example I saw was really more about how the View template generator couldn't reflect a LINQ2SQl generated class because it had some sort of circular reference... Actually I think it may have been JSON serialization in that case... Also, there have been several instances where an object has a member that's another class and visual studio couldn't generate a template for it. I guess its a somewhat different case than the one here, but I think the same principle may help
TJB
In general a ViewModel is much easier to deal with since you can encapsulate multiple entities (or map to your own objects). We use LLBL for a very large HR product built in ASP.NET MVC. It works really well for us.
Jess
+1  A: 

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:

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

then convert your controller method to

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

I like this approach because each ViewModel is an object in-and-of itself.

Ben Elder
This is what we do.
Jess
A: 

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

Dan Appleyard