problem using LLBL as the model

Posts   
 
    
quentinjs avatar
quentinjs
User
Posts: 110
Joined: 09-Oct-2009
# Posted on: 14-Oct-2009 08:55:36   

I am trying to use LLBL as the model as part of the MVC. My problem is in getting the data from a table called Group, and handing it off to the viewer. I get the error message:

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]'.

My Code is as follows (including some commented out variations I had attempted)

    private GroupCollection _gc = new GroupCollection();

    //
    // GET: /Home/

    public ActionResult Index()
    {

        _gc.GetMulti(null);
        //List<GroupEntity> gc = 
        //System.Collections.Generic.IEnumerable<GroupCollection> ii = _gc.AsEnumerable<GroupCollection>;
        //List<GroupCollection> gc = _gc.AsEnumerable<GroupCollection>;
        IEnumerable<GroupEntity> gList = _gc.ToList(); 
        //IList<glossary.CollectionClasses.GroupCollection> ii = _gc.AsEnumerable<glossary.CollectionClasses.GroupCollection>;

// List<GroupEntity> ge = new List<GroupEntity>();

        return View(gList);
     }

any suggestions would be welcome, I am sure this is easy to do :-)

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Oct-2009 10:45:26   
quentinjs avatar
quentinjs
User
Posts: 110
Joined: 09-Oct-2009
# Posted on: 14-Oct-2009 20:28:24   

Walaa wrote:

Please check this thread: http://stackoverflow.com/questions/868786/asp-net-mvc-how-to-bind-custom-model-to-view

Thanks, I took a look at it and the related links. I am not sure if its the arrayToContact thats throwing things, which in the LLBL world I think should be:

 private GroupCollection _gc = new GroupCollection();

 public class ContactsView{
    Object[] ContactsList { get; set;}
  }

and this...

 ViewData["contacts"] = new SelectList(gc.AsEnumerable);
       or 
 return View(new ContactsView() {ContactsList = _gc.ToArray<ContactsEntity>);

another link I tried following was:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=16446&HighLight=1

but I don't have anything like RoleCollectionViaUserRole. aka for me GroupCollectionVia______.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Oct-2009 12:43:56   

I don't have much experience with LLBLGen Pro usage in an MVC model. But as far as I understand, from the posted links, you need to return an Object[].

quentinjs avatar
quentinjs
User
Posts: 110
Joined: 09-Oct-2009
# Posted on: 18-Oct-2009 08:23:49   

So for those using LLBLGenPro for the model in MVC its easy to get it working.

In the controls area you need code similiar to this...

   private GroupCollection gc = new GroupCollection();

    //
    // GET: /Home/

    public ActionResult Index()
    {
       gc.GetMulti(null);
       return View(gc);
    }

The catch is that in the view creation you need the following

View - strongly typed. I used the List template. When selecting the type use the GroupEntity NOT the Collection.

This should help.