我有简单的类我怎么可以把自定义类的数组从阿贾克斯到ASP.NET MVC控制器
public class CaseField
{
public string XPath { get; set; }
public string NewValue { get; set; }
}
和控制器
public string SaveCaseData(string authority,
string shopNo,
string caseNo,
CaseField[] caseFields)
{
return new Service().SaveCaseData(authority,shopNo,caseNo,caseFields.ToList());
}
和jQuery Ajax请求
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();
}
});
我收到的前3个参数。但随着阵列我有问题 - 在我的浏览器我看editableFieldsArray和我有正确的数据阵列,但在控制器我有空值
编辑
阵列在Ajax调用铬我有这种结构的参数
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
在fireb ug:
哪里出错?
您的editableFieldsArray的JSON对象看起来像什么?那些字段是如何定义的? – villecoder 2012-02-29 18:13:26
你能告诉我们从Firebug发布的JSON吗? – SLaks 2012-02-29 18:15:50
我有更新我的问题 – 2012-02-29 18:26:26