CRUD and Model Binding

Hi guys,

We are just starting to have a play with the Syncfusion MVC components and I have a question about posting data back to the controller.

We have been using our own form controls for a while now, so binding data to a model and posting back to the controller has been quite easy.  EditorFor's etc used and all properties are set when the form is submitted back to the controller.  Using our own controls and editor templates mean we have a lot of control over the flow between the view and controller.

Now we are having a bit of play with Syncfusion, I'm struggling to find an example or doco to get the data bound properly to models when posting back.

An example of the sort of thing we would usually do:

  • Model with a number of properties, some of which could be a list of objects
  • View with a form with EditorFor's for the basic properties (boolean, strings, ints etc).  A for loop to loop through the list items to create editors, which results in the correct name being used in the html input control and therefore the model binder will pickup the values and they will be present in the model when it is passed back to the controller.  The view will have a submit/save button at the bottom of the form to submit the data back to the controller.
  • Controller that has a post action that accepts the model.  From here we do a DB store, or manipulate the model etc.
Obviously that is very high level...  

So far I haven't been able to find a good example of binding data to a complex model from a data grid and passing it back to controller.  I've seen some examples where people use ajax to build a string of the data grid to send back to the controller and another example where a list of changed models were passed back, but the actual values seemed to be missing.

I suppose I am after:
  1. How to properly create a grid from a list item that allows bulk edit and then send back the whole grid in custom model
  2. Is it possible to have a form with several items, including a grid, with a submit/save button and the form is submitted to the controller with all properties, including the list items from the grid, populated.
Thanks and hopeuflly that makes sense :)

5 Replies

WG Warrick Goddard November 20, 2021 08:35 AM UTC

I've managed to figure this out a little more.

After looking at some posts I can see that the Added, Changed and Deleted properties are important in the model and they are what the grid uses to bind the data.

Is it possible to get every row of the grid?  So an Unchanged property



AG Ajith Govarthan Syncfusion Team November 23, 2021 03:39 AM UTC

Hi Warrick, 

Thanks for contacting Syncfusion support. 

Based on your query, you want to use remote data in your Grid application and also wants to pass some additional information to the server side. So, before we proceed to your query, please share the below details to validate further on your requirement. 

  1. Please share the data adaptor used in your Grid application.

  1. Do you want to send additional data from the Grid component to the server side when you perform the CRUD operation?
 
  1. Do you want to use complex field data in your Grid application?
 
  1. Please share more details on the query “Is it possible to get every row of the grid?  So an Unchanged property”.
 
Regards, 
Ajith G. 



WG Warrick Goddard replied to Ajith Govarthan November 23, 2021 09:08 PM UTC

Hi Ajith,

Thanks for the reply :)


  1. I had been using the RemoteSaveAdaptor adaptor.
  2. The plan is yes to more data.  So the data in the grid would potentially only be one property of a parent model.  So for example I might have a PersonModel, with a string firstname, string lastname, int age and a list of HobbieModel's for example.  Hitting save on the form should submit all properties and set values to the controller, including every row of the grid that is bound to the HobbieModel, regardless of whether they have been added, deleted or updated.  
  3. Potentially, although at the moment I am just trying to get step 2 working :)
  4. See point 2.  Let's say the grid has 4 rows by default, set in the controller, and the user can update the data in the grid.  They might update rows 1 and 3, which will be in the updated list of models, but I also want to send rows 2 and 4, even though they have not been changed.  So 4 rows in, 4 rows out.
I hope that makes sense!

Cheers, Warrick.


AG Ajith Govarthan Syncfusion Team November 26, 2021 03:18 AM UTC

Hi Warrick, 

Thanks for the update. 

Based on your query, you want to send all the data along with CRUD data while update the changes at the server side. So, currently we are validating your requirement at our end and we will update further details on 26th November 2021. 

Until then we appreciate your patience. 

Regards, 
Ajith G. 



AG Ajith Govarthan Syncfusion Team November 29, 2021 03:35 AM UTC

Hi Warrick Goddard, 

Thanks for the update. 

Based on your query we could understand that you want to send all the data to the server side when you perform the CRUD actions with remote save adaptor. So, please share the exact use case of sending all the data to the server side and explain more details on your use case to provide you the prompt solution at the earliest.  

Regards, 
Ajith G. 
                                              


Loader.
Up arrow icon