This project is read-only.

Bind multiple grids

Jun 6, 2014 at 2:06 PM
I have two grids in a View and a foreach loop in a table and I need to bind them from a single ViewModel.
I have created a Repository Model that returns the data in IEnumerable format for each of the grids and table.
Please guide me as to how bind data in the grids and table using IEnumerable.

Priya K
Jun 22, 2014 at 8:36 AM

Create a ViewModel with 2 IEnumerable properties:
    public class MyViewModel
        public IEnumerable<MyGridItem> Grid1Items { get; set; }
        public IEnumerable<MyGridItem> Grid12tems { get; set; }
Then bind each grid to his collection in the view:
@model MyViewModel

@Html.Grid(Model.Grid1Items).Columns( .... )

@Html.Grid(Model.Grid2Items).Columns( .... )
See also