This is a migrated thread and some comments may be shown as answers.

Format Array for CRUD so MVC ModelBinder can read it

2 Answers 40 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
axwack
Top achievements
Rank 1
axwack asked on 09 Sep 2012, 01:49 AM
I am sending over an array to my MVC Controller and it seems to match the signature. However the array from my data source maps the value as such:

allocations[0][key]=value

The model is looking for the following: allocation[0].key=value.

Is there a way to rewrite the way the array will send out its value to the controller?

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Sep 2012, 02:22 PM
Hello Vincent,

I am not sure if I understand the exact scenario. If you are using the DataSource to send the data, you can use the parameterMap function to change the way the data is sent. We have a code library which demonstrates how to convert the data when using the Grid DataSource. You can check it on this page.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Nohinn
Top achievements
Rank 1
answered on 12 Sep 2012, 03:18 PM
As Daniel told you, you should use the parameterMap function of the dataSource:
dataSource: {
    parameterMap: function(options, action) {
         // your code here
         return options;
    }
}

In the options parameter you will have what the dataSource is actually sending to your controller. You should use the action parameter to know when you're reading, creating, ...

Looking at your requirements looks like your resulting options should be:
options = [];
options[0] = {};
options[0].key = value;

But be sure to work on another variable before losing the actual data in the options variable.
Tags
Data Source
Asked by
axwack
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Nohinn
Top achievements
Rank 1
Share this question
or