Format Array for CRUD so MVC ModelBinder can read it

3 posts, 0 answers
  1. axwack
    axwack avatar
    37 posts
    Member since:
    Aug 2012

    Posted 08 Sep 2012 Link to this post

    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. Daniel
    Admin
    Daniel avatar
    2230 posts

    Posted 12 Sep 2012 Link to this post

    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!
  3. Nohinn
    Nohinn avatar
    167 posts
    Member since:
    Feb 2011

    Posted 12 Sep 2012 Link to this post

    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.
Back to Top