【问题标题】:How can I send complex params to asp.net如何将复杂的参数发送到 asp.net
【发布时间】:2017-05-27 13:59:21
【问题描述】:

全部 我的软件结构是 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 c# asp.net extjs extjs3


【解决方案1】:

javascript 代码很好。您只需要修改服务器端代码。据我了解,当您发送以下数据时:

params: Ext.util.JSON.encode({ ids: [{ id: 11 },{ id: 12},{ id: 13}]})

服务器端将其视为您正在发送包含 ID 列表/数组的对象(表单数据)。

因此,在服务器端,您必须将其作为具有 ID 列表/数组作为属性的单个对象接收。即

public class IdStruct
{
    public List<int> id { get; set; }
}

public ActionResult ObjectReceive(IdStruct ids)
{
   return Content("{success:true}");
}

【讨论】:

  • 对不起,我还是一无所获
猜你喜欢
  • 2012-07-12
  • 1970-01-01
  • 1970-01-01
  • 2020-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多