Я пробую версию JQGrid ASP.NET MVC2.
Создана модель и контроллер:
var itemsGridModel = new OrderItemsjqGridModel();
itemsGridModel.OrderItemsGrid.DataUrl = Url.Action("ItemsDataRequested", new {OrderID = OrderID, CustomerID = CustomerID });
orderVM.orderItemsGrid = itemsGridModel;
return View(orderVM);
ItemsDataRequested:
public JsonResult ItemsDataRequested(int OrderID, int CustomerID)
{
// Get both the grid Model and the data Model
var gridModel = new OrderItemsjqGridModel();
var orderItems = ordersRepository.GetOrder(OrderID).ItemsInOrders.ToList();
IQueryable<ItemsInOrder> myItems = orderItems.AsQueryable<ItemsInOrder>();
return gridModel.OrderItemsGrid.DataBind(myItems);
}
Я получаюисключение NullReferenceException в последней строке.В myItems есть 1 элемент со всеми заполненными значениями.
Есть идеи, что я делаю не так?
Спасибо.
StackTrace:
at Trirand.Web.Mvc.Util.PrepareJsonResponse(JsonResponse response, JQGrid grid, DataTable dt)
at Trirand.Web.Mvc.Util.ConvertToJson(JsonResponse response, JQGrid grid, DataTable dt)
at Trirand.Web.Mvc.JQGrid.FilterDataSource(Object dataSource, NameValueCollection queryString, IQueryable& iqueryable)
at Trirand.Web.Mvc.JQGrid.GetJsonResponse()
at Trirand.Web.Mvc.JQGrid.DataBind()
at Trirand.Web.Mvc.JQGrid.DataBind(Object dataSource)
at TechRun.UI.Controllers.OrdersController.ItemsDataRequested(Int32 OrderID, Int32 CustomerID) in y:\work\yosi\source\Techrun\TechRun.UI\Controllers\OrdersController.cs:line 118
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
Модель:
public class OrderItemsjqGridModel
{
public JQGrid OrderItemsGrid { get; set; }
public OrderItemsjqGridModel()
{
OrderItemsGrid = new JQGrid
{
Columns = new List<JQGridColumn>()
{
new JQGridColumn { DataField = "OrderID",
// always set PrimaryKey for Add,Edit,Delete operations
// if not set, the first column will be assumed as primary key
PrimaryKey = true,
Editable = false,
Width = 30 },
new JQGridColumn { DataField = "ItemID",
PrimaryKey = true,
Editable = true,
Width = 120},
new JQGridColumn { DataField = "ItemDescription",
Editable = true,
Width = 300},
new JQGridColumn { DataField = "NumOfItems",
Editable = true,
Width = 50
},
new JQGridColumn { DataField = "CostOfItem",
Editable = true,
Width = 75 },
new JQGridColumn { DataField = "TotalCost",
Editable = false
},
new JQGridColumn { DataField = "SuppolyDate",
Editable = true,
Width = 120,
DataFormatString = "{0:d}" },
},
Width = Unit.Pixel(640),
Height = Unit.Percentage(100)
};
OrderItemsGrid.ToolBarSettings.ShowRefreshButton = true;
OrderItemsGrid.ToolBarSettings.ShowAddButton = true;
OrderItemsGrid.ToolBarSettings.ShowDeleteButton = true;
OrderItemsGrid.ToolBarSettings.ShowEditButton = true;
}
}