MVC Contrib Grid populate without model
-
04-03-2021 - |
質問
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?
解決
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(...)
所属していません StackOverflow