Question

I am looking at an example of how to use MVC Contrib Grid :

http://www.4guysfromrolla.com/articles/031611-1.aspx

I am already using a @model on the page for something else, and I want to be able to create up to 6 grids on my page. Is it possible to pass a method that returns the grid contents to the Grid object?

Was it helpful?

Solution

You can pass any number of collections from the controller action to the view through ViewData or ViewBag.

public ActionResult Index()
{
   ViewData["foos"] = GetFoos();
   ViewData["bars"] = GetBars();
   ViewData["bazz"] = GetBazz();

   return View(/*model*/);
}

And in the view

@Html.Grid((IEnumerable<Foo>)ViewData["foos"]).Columns(...)
@Html.Grid((IEnumerable<Bar>)ViewData["bars"]).Columns(...)
@Html.Grid((IEnumerable<Bazz>)ViewData["bazz"]).Columns(...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top