简体   繁体   中英

How can I send complex params to asp.net

all My software struct is Extjs3.4.1 + Asp.net Mvc3. Now I want send object from client to server

Below is javascript code:

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();
        });

And below is code on server side

public class IdStruct
{
    public int id { get; set; }
}

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

The result is method ObjectReceive excuted,but ids is nothing

My question is how can I send complex params to asp.net

The javascript code is fine. You just have to modify the Server side code. From my understanding, when you are sending the following data:

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

The server side take it as your are sending an object (Form Data) that contains the List/Array of ids .

So at Server side, you have to receive it as a Single Object having List/Array of ids as property. ie

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM