Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I bind my view model to a jqGrid?
    primarykey
    data
    text
    <p>Using MVC2 and EF framework. Most references/blog posts I've found so far pertain to binding a single table and its data (sometimes hierarchical) to a jqGrid with editing capabilities. I don't need this. I don't even need to edit the data--just display. I need to display and page the data. Sorting is a plus, searching a bonus I guess.</p> <p>jqGrid's documentation shows the data source being bound as follows:</p> <pre><code>return gridModel.OrdersGrid.DataBind(northWindModel.Orders); </code></pre> <p>But, I only have my Entities context without a reference to the view model. Could I create an Entity set here? Not very familiar with this.</p> <p>All my view models contain data from several different tables. What can I do to bind the view model properties to a jqGrid? I'm playing with <a href="http://www.trirand.net/default.aspx">Trirand</a>'s 30-day trial of jqGrid for MVC. Again, I just need to <em>display and page</em> the data, but I'm not sure how to hook up the view models to the jqGrid data source.</p> <h2>Edit</h2> <pre><code>public ActionResult test() { var gridModel = new testmodel(); var viewModel = gridModel.testgrid; SetupTestGrid(viewModel); return View(gridModel); } private void SetupTestGrid(JQGrid viewModel) { viewModel.ID = "TestGrid"; viewModel.DataUrl = Url.Action("SearchTestGridDataRequested"); viewModel.ToolBarSettings.ShowEditButton = false; viewModel.ToolBarSettings.ShowAddButton = false; viewModel.ToolBarSettings.ShowDeleteButton = false; } public JsonResult SearchTestGridDataRequested(string sidx, string sord, int page, int rows) { var gridModel = new testmodel(sidx, sord, page, rows); SetupTestGrid(gridModel.testgrid); return Json(gridModel.datasource); } </code></pre> <p>In testmodel and testmodel(parameters), I create an anonymous type (named datasource) containing <a href="http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx">Phil Haack's</a> parameters; total, page, records and rows. This property is JSON'ified in the last statement of SearchTestGridDataRequested.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload