I have simple class

 public class CaseField
    {
        public string XPath { get; set; }
        public string NewValue { get; set; }
    }

And controller

 public string SaveCaseData(string authority, 
                            string shopNo, 
                            string caseNo, 
                            CaseField[] caseFields)
        {
            return new Service().SaveCaseData(authority,shopNo,caseNo,caseFields.ToList());
        }

And jQuery ajax request

var editableFieldsArray = [];

   $('.editable').each(
            function () {
                var caseField = {};
                caseField.NewValue = $(this).attr("value");
                caseField.XPath = $(this).attr("xpath");
                editableFieldsArray.push(caseField);
            }
        );
var params = { authority: authority, shopNo: shopNum, caseNo: caseNum, caseFields: editableFieldsArray };
        $.ajax({
            url: $('.CaseDataView').data('url'),
            datatype: 'json',
            data: params,

            success: function (result) {

                isDataChanged = false;

                if (showOperationResult) {
                    if (result == 'Successful') {
                        jAlert('Case data saved succesfully!', '', 'BigInfoIcon');
                    } else if (result == 'Failed') {
                        jAlert('Failed to save case data!', '', 'BigInfoIcon');
                    }
                }

                HideChangeProcess();
            }
        });

First 3 params i receive. But with array i have problem - in my browser i look at editableFieldsArray and i have array with correct data, but in controller i have array with null values
enter image description here


EDIT
Before ajax call in chrome i have this structure of params

params
Object
authority: "localhost"
caseFields: Array[3]
0: Object
NewValue: "Thurid Waagstein Madsen"
XPath: "Case/SalesInfo/Customers/CustomerContactInfo/Name"
__proto__: Object
1: Object
NewValue: "Holger Danskes Vej 79"
XPath: "Case/SalesInfo/Customers/CustomerContactInfo/Address"
__proto__: Object
2: Object
NewValue: "Frederiksberg"
XPath: "Case/SalesInfo/Customers/CustomerContactInfo/City"
__proto__: Object
length: 3
__proto__: Array[0]
caseNo: "06659"
shopNo: "N100250"
__proto__: Object

In firebug:

enter image description here Where is mistake ?

link|improve this question

What do your JSON objects for editableFieldsArray look like? How are those fields defined? – villecoder Feb 29 at 18:13
1  
Can you show us the POSTed JSON from Firebug? – SLaks Feb 29 at 18:15
I have update my question – andronz Feb 29 at 18:26
feedback

1 Answer

You need to change the traditional property to true so that it passes the array values correctly:

$.ajax({
    url: $('.CaseDataView').data('url'),
    datatype: 'json',
    data: params,
    traditional: true,
    ...

If you want to do this for all ajax calls you can just add this instead:

jQuery.ajaxSetting.traditional = true;

You can find some background info here.

link|improve this answer
If i use traditional: true i receive null, if traditional : false i receive array with 3 elements with null values – andronz Mar 1 at 11:19
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.