Ejemplo n.º 1
0
        public ActionResult EditRows(Order editedOrder)
        {
            // Get the grid and database (northwind) models
            var gridModel = new OrdersJqGridModel();
            var northWindModel = new NorthwindDataContext();

            // If we are in "Edit" mode
            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                // Get the data from and find the Order corresponding to the edited row
                Order order = (from o in northWindModel.Orders
                               where o.OrderID == editedOrder.OrderID
                               select o).First<Order>();

                // update the Order information
                order.OrderDate = editedOrder.OrderDate;
                order.CustomerID = editedOrder.CustomerID;
                order.Freight = editedOrder.Freight;
                order.ShipName = editedOrder.ShipName;

                northWindModel.SubmitChanges();
            }
            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                // since we are adding a new Order, create a new istance
                Order order = new Order();
                // set the new Order information
                order.OrderID = (from o in northWindModel.Orders
                                 select o)
                                .Max<Order>(o => o.OrderID) + 1;
                order.OrderDate = editedOrder.OrderDate;
                order.CustomerID = editedOrder.CustomerID;
                order.Freight = editedOrder.Freight;
                order.ShipName = editedOrder.ShipName;

                northWindModel.Orders.InsertOnSubmit(order);
                northWindModel.SubmitChanges();
            }
            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                Order order = ( from o in northWindModel.Orders
                                where o.OrderID == editedOrder.OrderID
                                select o)
                               .First<Order>();

                // delete the record
                northWindModel.Orders.DeleteOnSubmit(order);
                northWindModel.SubmitChanges();
            }

            return RedirectToAction("GridDemo", "Grid");
        }
Ejemplo n.º 2
0
        public ActionResult GridDemo()
        {
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new OrdersJqGridModel();
            var ordersGrid = gridModel.OrdersGrid;

            // customize the default Orders grid model with custom settings
            // NOTE: you need to call this method in the action that fetches the data as well,
            // so that the models match
            SetUpGrid(ordersGrid);

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }
Ejemplo n.º 3
0
        // This method is called when the grid requests data
        public JsonResult SearchGridDataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new OrdersJqGridModel();
            var northWindModel = new NorthwindDataContext();

            // customize the default Orders grid model with our custom settings
            SetUpGrid(gridModel.OrdersGrid);

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
            return gridModel.OrdersGrid.DataBind(northWindModel.Orders);
        }