I have 3 igGrids which allow updating and some textboxes on a View.
When user make changes I want to post the grid changes and Model to the controller.
I have tried wrapping all the controls inside a Html.BeginForm and passing the model to the controller on submit, but the igGrid transactions are not coming thourgh.
Note, that I know how to use .UpdateUrl(Url.Action("BomSaveChanges", "Model")) to pass Iggrid transactions one by one but I need the transactions from all iggrids and the Model to be passed to controller. See code below:
View
@model BomCollectionViewModel@{ ViewBag.Title = "Bom";
var bomCode = (Model.BomList.FirstOrDefault() == null ? 0 : Model.BomList.FirstOrDefault().BomCode);}@Html.ScriptsAndStyles(new List<string> { "grid" }, "infragistics")@using (Html.BeginForm("BomSaveChanges", "Model", FormMethod.Post)){ @Html.HiddenFor(model => model.Code)
@Html.Label("Sku Name") @Html.TextBoxFor(m => m.SkuName)
@Html.Label("BoM Name") @Html.TextBoxFor(m => m.Name) <div id="bomForm"> <div id="rawMaterials"> @(Html.Infragistics() .Grid(Model.BomList.AsQueryable()) .ID("rmGrid") .PrimaryKey("Code") .UpdateUrl(Url.Action("BomSaveChanges", "Model", new { bomCode = @bomCode })) .Width("50%") .Height("200px") .AutoGenerateColumns(false) .AutoGenerateLayouts(false) .Columns(column => { column.For(x => x.Code).HeaderText("Bom Item Code").Width("20%"); column.For(x => x.Name).HeaderText("Bill of Materials").Width("30%"); column.For(x => x.Weight).HeaderText("Weight").Width("30%"); column.For(x => x.Proportion).HeaderText("Proprotion").Width("20%"); }) .Features(feature => { feature.Updating().ColumnSettings(cs => { cs.ColumnSetting().ColumnKey("Code").EditorType(ColumnEditorType.Numeric).ReadOnly(true); cs.ColumnSetting().ColumnKey("Name").EditorType(ColumnEditorType.Text).Required(true); cs.ColumnSetting().ColumnKey("Weight").EditorType(ColumnEditorType.Numeric).Required(true); cs.ColumnSetting().ColumnKey("Proportion").EditorType(ColumnEditorType.Numeric).Required(true);
}); feature.Sorting(); }) .DataBind() .Render() ) </div> <div id="SkuPackaging"> @(Html.Infragistics() .Grid(Model.BomList.AsQueryable()) .ID("spGrid") .PrimaryKey("Code") .UpdateUrl(Url.Action("BomSaveChanges", "Model")) .Width("50%") .Height("200px") .AutoGenerateColumns(false) .AutoGenerateLayouts(false) .Columns(column => { column.For(x => x.Code).HeaderText("Bom Item Code").Width("10%"); column.For(x => x.Name).HeaderText("Bill of Materials").Width("30%"); column.For(x => x.Weight).HeaderText("Weight").Width("30%"); column.For(x => x.Proportion).HeaderText("Proprotion").Width("20%"); }) .Features(feature => { feature.Updating().ColumnSettings(cs => { cs.ColumnSetting().ColumnKey("Code").EditorType(ColumnEditorType.Numeric).ReadOnly(true); cs.ColumnSetting().ColumnKey("Name").EditorType(ColumnEditorType.Text).Required(true); cs.ColumnSetting().ColumnKey("Weight").EditorType(ColumnEditorType.Numeric).Required(true); cs.ColumnSetting().ColumnKey("Proportion").EditorType(ColumnEditorType.Numeric).Required(true);
}); feature.Sorting(); }) .DataBind() .Render() ) </div> <div id="CasePackaging"> @(Html.Infragistics() .Grid(Model.BomList.AsQueryable()) .ID("cpGrid") .PrimaryKey("Code") .UpdateUrl(Url.Action("BomSaveChanges", "Model")) .Width("50%") .Height("200px") .AutoGenerateColumns(false) .AutoGenerateLayouts(false) .Columns(column => { column.For(x => x.Code).HeaderText("Bom Item Code").Width("10%"); column.For(x => x.Name).HeaderText("Bill of Materials").Width("30%"); column.For(x => x.Weight).HeaderText("Weight").Width("30%"); column.For(x => x.Proportion).HeaderText("Proprotion").Width("20%"); }) .Features(feature => { feature.Updating().ColumnSettings(cs => { cs.ColumnSetting().ColumnKey("Code").EditorType(ColumnEditorType.Numeric).ReadOnly(true); cs.ColumnSetting().ColumnKey("Name").EditorType(ColumnEditorType.Text).Required(true); cs.ColumnSetting().ColumnKey("Weight").EditorType(ColumnEditorType.Numeric).Required(true); cs.ColumnSetting().ColumnKey("Proportion").EditorType(ColumnEditorType.Numeric).Required(true);
}); feature.Sorting(); }) .DataBind() .Render() ) </div> <br /> <input type="submit" id="saveChanges" value="BomSaveChanges" /> <input type="button" id="undo" class="button-style" value="Undo" /> <input type="button" id="redo" class="button-style" value="Redo" /> <br /> </div>}
Controller:
[HttpPost] public ActionResult BomSaveChanges(BomCollectionViewModel bomCollection) { int id = 0; var allBoms = new CostAnalyticsSchema.mt_ca_data_ModelBomDataTable(); AppInfrastructure.DataTableSelect(allBoms);
if (id > 0) { bool isNewBom = allBoms.Any(s => s.BomCode == id); }
ViewData["GenerateCompactJSONResponse"] = false;
GridModel m = new GridModel();
List<Transaction<BomViewModel>> transactions = m.LoadTransactions<BomViewModel>(HttpContext.Request.Form["ig_transactions"]);
etc..
Hello,
Thank you for using our forum! About the issue that you've mentioned, regarding igGrid transactions not coming through, my suggestion is to use hidden field, which will pass the transaction to the begin form like this:
I've attached you a sample that is showing this approach.
If you have any further questions do not hesitate to contact me.
Hi Zdravko,
The example project you have attached does not seem to be related to the issue you are addressing - e.g. there is no grid at all in the attached sample project. I'd like to see a working example of the grid transactions being posted back as part of the model to a MVC controller to allow updating all grid updates in a batch rather than in a CRUD single update at a time scenario.
Thanks.