所有 我的软件结构是Extjs3.4.1 + Asp.net Mvc3。 现在我想要从客户端发送对象到服务器
以下是javascript代码:
Ext.getCmp("hiddenform").getForm().submit({
method: 'POST',
waitTitle: 'Connecting',
timeout: 180,
waitMsg: 'Sending data...',
params: Ext.util.JSON.encode({ ids: [{ id: 11 },{ id: 12},{ id: 13}]}),
url: myroot + 'stock/ObjectReceive',
success: function (form, action) {
Ext.Msg.alert("success", "success", function () {
pwforqueryconditions.hide();
});
},
failure: function (form, action) {
itemform.getForm().reset();
});
以下是服务器端的代码
public class IdStruct
{
public int id { get; set; }
}
public ActionResult ObjectReceive(List<IdStruct> ids)
{
return Content("{success:true}");
}
结果是方法ObjectReceive被执行,但是id不是什么
我的问题是如何将复杂的参数发送到asp.net
答案 0 :(得分:1)
javascript代码很好。您只需修改服务器端代码即可。根据我的理解,当您发送以下数据时:
params: Ext.util.JSON.encode({ ids: [{ id: 11 },{ id: 12},{ id: 13}]})
服务器端将其视为您发送的对象(表单数据),其中包含列表/数组ID 。
因此,在服务器端,您必须将其作为具有List / Array ofID作为属性的单个对象接收。即。
public class IdStruct
{
public List<int> id { get; set; }
}
public ActionResult ObjectReceive(IdStruct ids)
{
return Content("{success:true}");
}