I'm trying to use the IgniteUI Grid control with MVC. The data appears in the Grid properly when viewing, but when I call my Edit ActionResult method in my controller to save the view back to the model, the property that is bound to the Grid comes back as being null while all other fields have their correct values. The Grid only renders a single property of the model, not the entire thing. I cannot figure out what I need to do in order to get the Grid to push its data into the view and back to the model when saving.
I have attached a stripped down example of what I am trying to do. The real code has a lot more properties, all of which get their correct values except for the Grid.
Any suggestions as to how I can the Grid data to be sent back with everything else? Do I need to call something in order for the Grid to save its data so that it's sent back with the rest of the view data?
Thanks.
Hello Keith,
Thank you for posting in our community.
I believe that the following article from our documentation regarding Updating overview will help you achieve better understanding how igGrid Updating feature works.
http://www.igniteui.com/help/iggrid-updating
Basically, igGrid communicates with igGrid MVC Helper wrapper to persist changes on the server. This feature uses transactions to log changes made to the grid. These transactions are kept locally in the browser until the igGrid.saveChanges API method is called to send a POST request to the Url indicated by the grid.updateUrl option. On the server these transaction should be parsed and processed and the igGrid MVC helper wrapper greatly simplifies this task. A working sample illustrating how basic editing works could be found at the following link:
http://www.igniteui.com/grid/basic-editing
I hope you find my information helpful.
Please let me know if you need any further assistance with this matter.
From the looks of the article and what you're saying then, it seems that the only way to update the data in the Grid is to use specify a controller action using UpdateUrl; there is no way to simply pass the Grid's data back with the rest of the view's data? Is that correct? That would seem like a fairly major limitation, especially for the project I'm working on. My rows need to be associated a parent record - this becomes problematic when creating a new parent record as the Grid will not yet know the ID of the parent record and the UpdateUrl method runs independently of the controller's Create action. Not including the Grid on the create page is not an option. So if the Grid requires UpdateUrl and cannot pass it back with the rest of the view's data, it would seem that I might be stuck.
In short, it looks like the Grid reads from the model, but it cannot write back to the model and can only persist back to the database.
The igGrid is not directly associated with the MVC Model and will not automatically update the associated collection.
If you wish to apply some other mechanism of saving the changes (different than using the UpdateUrl option and saving the changes in the related Action on the server) you could directly get the transactions on the client side (http://help.infragistics.com/jQuery/2015.1/ui.iggrid#methods:pendingTransactions ) and send them as part of the request to your Edit ActionResult method. Note that the method for deserializing that data would be similar to the one demonstrated in the online sample : http://www.igniteui.com/grid/basic-editing For example: GridModel gridModel = new GridModel();List<Transaction<Order>> transactions = gridModel.LoadTransactions<Order>(HttpContext.Request.Form["ig_transactions"]);
Pleas let me know if you need any further assistance with this matter.
Thanks for the info, Vasya! It helped point me in the right direction and I've managed to get everything serialized and can push it back into model using the controller's ActionResult.
Thank you for your feedback.
I am glad that you find my suggestion helpful.