I am using the igGrid using the Grid Model approach. After Updating/Editing the grid post to an MVC controller. I would like an example how to handle Server Side errors and displaying the error to the returned View.
Thanks
Hello Eric,
Thank you for posting in our forum.
There are several different approaches that might be applicable, so I would appreciate some additional information with regard to your scenario:
Providing me those details would be greatly appreciated as it would allow me to get a better idea of the requirements you have, as well as the specifics of your web application.
I look forward to your reply.
Thanks Vasil,
Here is where I'm at so far.
I can get notification of server-error back from the request now. But, I want to be able to display the message; either as a modal or (as a ModelState error does) embedded in the view. If Unsuccessful, then display the error and scroll the grid back to the top, leaving changed data intact. If Successful, redirect to another view.
View.cshtml
@(Html.Infragistics().Grid(Model.PayIncreasePrevi <div class="row content-footer"> <div class="col-xs-12"> <ul class="pager pull-right"> <li> <button id="saveChanges" type="submit" class="btn btn-primary" value="Save">Perform Pay Increase</button> </li> </ul> </div> </div> @section Scripts{ <script type="text/javascript"> (function ($) { $(function () { $("#saveChanges").bind({ click: function (e) { $("#PayIncreasePreview").igGrid("saveChanges", function(result) { console.log(result); }); return false; } }); }); })(jQuery); </script> }
Controller.cs
[HttpGet] public ActionResult IncrementalPayIncreasePreview() { var model = _modelBuilder.BuildIncrementalPayIncreasePreviewModel(this.CurrentUser.CompanyID, this.CurrentUser.UserID); model.PayIncreasePreviewItems = GetPayIncreasePreviewGridModel(); return this.View("IncrementalPayIncreasePreview", model); } [HttpPost] public ActionResult IncrementalPayIncreasePreview(IncrementalPayIncreasePreviewModel model) { var defaultModel = _modelBuilder.BuildIncrementalPayIncreasePreviewModel(this.CurrentUser.CompanyID, this.CurrentUser.UserID); return this.View("IncrementalPayIncreasePreview", defaultModel); } private GridModel GetPayIncreasePreviewGridModel() { //define PayGrade layout GridModel payIncreasePreviewLayout = new GridModel(); payIncreasePreviewLayout.ID = "PayIncreasePreview"; payIncreasePreviewLayout.PrimaryKey = "SystemAssignedPersonID"; payIncreasePreviewLayout.Width = "100%"; //payIncreasePreviewLayout.AutoGenerateLayouts = false; //payIncreasePreviewLayout.AutoGenerateColumns = false; payIncreasePreviewLayout.AutofitLastColumn = true; payIncreasePreviewLayout.RenderCheckboxes = true; payIncreasePreviewLayout.EnableResizeContainerCheck = true; payIncreasePreviewLayout.AnimationDuration = 100; payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "CompanyID", HeaderText = "Company ID", HeaderCssClass = "columnheader", DataType = "string", Width = "100%", Hidden = true }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "CompanyName", HeaderText = "Company Name", DataType = "string", Width = "100%" }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "SystemAssignedPersonID", HeaderText = "SystemAssignedPersonID", DataType = "number", Width = "100%", Hidden = true }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "UserAssignedEmployeeID", HeaderText = "Employee ID", DataType = "string", Width = "100%" }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "EmployeeName", HeaderText = "Employee Name", DataType = "string", Width = "100%" }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "PayGradeID", HeaderText = "Pay Grade ID", DataType = "string", Width = "100%", Hidden = true }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "PayGradeDescription", HeaderText = "Pay Grade", DataType = "string", Width = "100%" }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "CurrentPayRateHourly", HeaderText = "Current Pay Rate Hourly", DataType = "number", Width = "100%" }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "NewPayRateHourly", HeaderText = "New Pay Rate Hourly", DataType = "number", Width = "100%" }); payIncreasePreviewLayout.Columns.Add(new GridColumn() { Key = "IsSelected", HeaderText = "Apply Pay Increase", DataType = "bool", Width = "100%" }); payIncreasePreviewLayout.UpdateUrl = Url.Action("PerformPayIncrease", "MassGlobalUpdate"); //data source payIncreasePreviewLayout.DataSource = GetPayIncreasePreview().AsQueryable(); //features //sorting GridSorting sorting = new GridSorting(); sorting.Type = OpType.Local; payIncreasePreviewLayout.Features.Add(sorting); //updating GridUpdating updatingPayIncrease = new GridUpdating(); updatingPayIncrease.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "CompanyName", ReadOnly = true }); updatingPayIncrease.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "UserAssignedEmployeeID", ReadOnly = true }); updatingPayIncrease.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "EmployeeName", ReadOnly = true }); updatingPayIncrease.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "PayGradeDescription", ReadOnly = true }); updatingPayIncrease.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "CurrentPayRateHourly", ReadOnly = true }); updatingPayIncrease.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "NewPayRateHourly", EditorType = ColumnEditorType.Currency }); updatingPayIncrease.EditMode = GridEditMode.Row; updatingPayIncrease.EnableAddRow = false; updatingPayIncrease.EnableDeleteRow = false; payIncreasePreviewLayout.Features.Add(updatingPayIncrease); //resizing GridResizing resizing = new GridResizing() { AllowDoubleClickToResize = true }; payIncreasePreviewLayout.Features.Add(resizing); //responsive GridResponsive responsive = new GridResponsive() { ForceResponsiveGridWidth = true }; payIncreasePreviewLayout.Features.Add(resizing); ////moving //GridColumnMoving columnMoving = new GridColumnMoving(); //payIncreasePreviewLayout.Features.Add(columnMoving); return payIncreasePreviewLayout; } private List<PayIncreasePreviewItem> GetPayIncreasePreview() { var employeesDueForIncrease = _employeeService.GetIncrementalPayIncreaseEmployees(this.CurrentUser.CompanyID, this.CurrentUser.UserID); return employeesDueForIncrease; } public ActionResult PerformPayIncrease() { JsonResult result = new JsonResult(); Dictionary<string, bool> response = new Dictionary<string, bool>(); GridModel gridModel = new GridModel(); List<Transaction<PayIncreasePreviewItem>> exportFileTransactions = gridModel.LoadTransactions<PayIncreasePreviewItem>(HttpContext.Request.Form["ig_transactions"]); var payInfos = new List<PayInfo>(); foreach (Transaction<PayIncreasePreviewItem> t in exportFileTransactions) { if (t.type == "row") { var oPayInfo = _employeeService.GetPayInfos(this.CurrentUser.CompanyID, this.CurrentUser.UserID, t.row.SystemAssignedPersonID).OrderByDescending(x => x.PayChangeEffectiveDate).FirstOrDefault(); var payInfo = new PayInfo() { SystemAssignedPersonID = oPayInfo.SystemAssignedPersonID, CompanyID = oPayInfo.CompanyID, PayChangeEffectiveDate = DateTime.Now, PayChangeReasonID = "INCREMENT", PayRateHourly = oPayInfo.PayRateHourly + t.row.NewPayRateHourly, PayPeriodSalary = t.row.NewPayRateHourly * oPayInfo.StandardHoursPerPayPeriod, //AnnualSalary = (t.row.NewPayRateHourly * oPayInfo.StandardHoursPerPayPeriod) * Convert.ToDecimal(oPayInfo.PayFrequencyID), //need pay frequency weeks }; payInfos.Add(payInfo); } //execute update try { _employeeService.UpdateIncrementalPayIncreaseEmployees(this.CurrentUser.CompanyID, this.CurrentUser.UserID, payInfos); } catch { //response.Add("Success", true); //result.Data = response; //return result; } } response.Add("Success", true); result.Data = response; return result; }