[Ajax] Pass the JSON object to the MVC background analysis

It is often necessary to pass an array collection to the background when making batch deletions or batch modifications.

At this time, you need to considerHow to submit a JSON array to the background with Ajax in front, and how to get in the background.

Of course, it is also possible to use a splicing string and then split in the background. But there is a better way

First, AJAX submission part

Var jsondata = []; // array, store data collection to be submitted
for (var i = 0; i < row.length; i++) {
         // Construct an object
    var arr = {
        EG_ID: row[i].EG_ID,
        EG_MyNum: row[i].EG_MyNum,
    }
         // store the object in the data set
    jsonData.push(arr);
}

$.getJSON("@Url.Action("myDataExchang", "ExchangLogs")", {
         // Convert the submitted data into JSON object
    jsonData: JSON.stringify(jsonData),
}, function (msg) {
    DJMask.msg(msg);
}, "text");


Second, the MVC controller gets data

public ActionResult myDataExchang()
{
    / / Get submitted data
    string data = Request["jsonData"];
    JavaScriptSerializer jss = new JavaScriptSerializer();
         / / Convert a string to json - "EGLIST object
    List<EGList> list = jss.Deserialize<List<EGList>>(data);
         // Other operations ...
}

Quote: using system.web.script.serialization;


three, eGlist class

public class EGList
{
    public int EG_ID { get; set; }
    public int EG_MyNum { get; set; }
}






Intelligent Recommendation

Ajax pass parameter json object to servlet to get

JSP login interface code: The corresponding code snippet of the servlet corresponding ajax value:  ...

$ .Ajax pass a string to the background, background objects return json

Here is the record I am using ajax to send data to the background, do the corresponding business logic operations backstage after receiving the data; the great God is ignored, the spray would not have...

js pass a json object to a php background

Reception php background...

How to pass values ​​to the background without Ajax Spring MVC

Idea: 1, the data to be transferred into the array 2, create a hidden form 3. Traverse the array, create a hidden <input> in the hidden form and assign it 4, submit the form  ...

.Net ajax using the internet to pass values ​​to the background of the method in mvc

1, HTML part of the code   2, js part 3, background method  ...

More Recommendation

ASP.NET MVC receiving a pass over the json data from ajax

Since the model binding receives the data is often a problem, so we use the original method of receiving data submitted over with ajax from the front desk: The following sample code: Reception: Backgr...

Ajax passes json object array to the background

javascript code Receive parameter code in background Entity class...

springMVC, foreground ajax pass JSON array parameters, how to receive background

Background sections: // json package used: com.alibaba.fastjson...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top