How do I get a linq to sql group by query into the asp.net mvc view?

Posted by Brad Wetli on Stack Overflow See other posts from Stack Overflow or by Brad Wetli
Published on 2009-12-23T03:29:36Z Indexed on 2010/06/11 17:02 UTC
Read the original article Hit count: 295

Sorry for the newbie question, but I have the following query that groups parking spaces by their garage, but I can't figure out how to iterate the data in the view. I guess I should strongly type the view but am a newbie and having lots of problems figuring this out. Any help would be appreciated.

    Public Function FindAllSpaces() Implements ISpaceRepository.FindAllSpaces
    Dim query = _
    From s In db.spaces _
    Order By s.name Ascending _
    Group By s.garageid Into spaces = Group _
    Order By garageid Ascending

    Return query

End Function

The controller is taking the query object as is and putting it into the viewdata.model and as stated the view is not currently strongly typed as I haven't been able to figure out how to do this. I have run the query successfully in linqpad.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about vb.net