全部 我的软件结构是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方法,但ids什么都没有
我的问题是如何将复杂的参数发送到asp.net
最佳答案
JavaScript 代码很好。您只需要修改服务器端代码即可。据我了解,当您发送以下数据时:
params: Ext.util.JSON.encode({ ids: [{ id: 11 },{ id: 12},{ id: 13}]})
服务器端将其视为您正在发送一个包含ID 列表/数组的对象(表单数据)。
因此,在服务器端,您必须将其作为单个对象接收,并将 ids 列表/数组作为属性。即
public class IdStruct
{
public List<int> id { get; set; }
}
public ActionResult ObjectReceive(IdStruct ids)
{
return Content("{success:true}");
}
关于javascript - 如何将复杂的参数发送到asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44217737/