Using AJAX to pass JSON arrays in MVC

Source: Internet
Author: User

Workaround

Go to www.json.org download json2.js
Then call Json.stringify (Jsondata) to convert the JSON object into a JSON string.

var people = [{"UserName": "T1", "PassWord": "111111", "Sex": "Male"}, {"UserName": "T2", "PassWord": "222222", "Sex": "Female" }];

Re-construct the URL back to the server side:
$ ("#btnSend"). Bind ("click", Function () {
$.post ("A.ashx", {xxxx:JSON.stringify (People)}, function (data, returnstatus) {}, "JSON");
});

functionCustomercheck () {selectrows= $ ("#ui_customerCheck_dg"). DataGrid (' Getselections '); varJsondata =json.stringify (selectrows);                    Console.info (Jsondata); if(Selectrows.length > 0) {console.info (selectrows); $.ajax ({URL:' Ashx/bg_customercheck.ashx?action=checkedpass ', data: {"Selectrows": Jsondata}, DataType:' HTML ', Success:function(rData) {varDatajson = eval (' (' + rData + ') ');//turn into JSON format                                if(datajson.success) {$.show_warning (Prompted, datajson.msg); $("#ui_customerCheck_dg"). DataGrid ("Reload"). DataGrid (' Clearselections '). DataGrid (' clearchecked '); } Else{$.show_warning (Prompted, datajson.msg);                    }                            }                        }); }                    Else{$.show_warning ("Prompt", "Please select the document that needs to be audited!" "); return; }                    //Console.info (selectrows);                    //$ ("#ui_customerCheck_dg"). DataGrid (' Unselectall ');                }
usingSystem;usingSystem.Collections.Generic;usingsystem.web;usingLT. Epc. BLL;usingLT.EPC.Common;usingLT. Epc. Model;usingLT. Epc. Sqlserverdal;namespaceLT. Epc. webui.admin.ashx{/// <summary>    ///Summary description of Bg_customercheck/// </summary>     Public classBg_customercheck:ihttphandler { Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Application/json"; stringAction = context. request.params["Action"]; Useroperatelogdatacontract Useroperatelog=NULL;//Action Log Object            Try{userdatacontract User= Userhelper.getuser (context);//get the user object in the cookieUseroperatelog =Newuseroperatelogdatacontract (); Useroperatelog.userip=Commonhelper.getip (context.                request.userhostaddress); Useroperatelog.username=user.                UserId; Switch(action) { Case "Checkedpass":                        varSelectrowsjson = context. request.params["selectrows"] ??""; List<UserDataContract> userlist =deserializeuserlist (Selectrowsjson); List<CustomerCheckDataContract> checklist =deserializechecklist (Selectrowsjson); if(Newcustomercheckmgr (). Changeorderstatus (Checklist)) {Useroperatelog.operateinfo="Customer Service Audit"; Useroperatelog.ifsuccess=true; Useroperatelog.description="Audit through"+NULL; Context. Response.Write ("{\ "msg\": \ "Audit passed! \ ", \" Success\ ": true}"); }                        Else{useroperatelog.operateinfo="Customer Service Audit"; Useroperatelog.ifsuccess=false; Useroperatelog.description="Customer serviceAudit Failure"; Context. Response.Write ("{\ "msg\": \ "Customer Service Audit failed! \ ", \" Success\ ": false}");                        } useroperatelogmgr.insertoperateinfo (Useroperatelog);  Break; default: Context. Response.Write ("{\ "result\": \ "parameter Error! \ ", \" Success\ ": false}");  Break; }            }            Catch(Exception ex) {context. Response.Write ("{\ "msg\": \ ""+ Jsonhelper.stringfilter (ex. Message) +"\ ", \" Success\ ": false}"); Useroperatelog.operateinfo="Customer Service Audit function Exception"; Useroperatelog.ifsuccess=false; Useroperatelog.description=Jsonhelper.stringfilter (ex.                Message);            Useroperatelogmgr.insertoperateinfo (Useroperatelog); }        }         Public BOOLisreusable {Get            {                return false; }        }        //convert JSON directly into an entity object         PublicList<userdatacontract> Deserializeuserlist (stringJSON) {            varU = jsonhelper.fromjson<list<userdatacontract>>(JSON); returnu; }        //convert JSON directly into an entity object         PublicList<customercheckdatacontract> Deserializechecklist (stringJSON) {            varo = jsonhelper.fromjson<list<customercheckdatacontract>>(JSON); returno; }    }}

Using AJAX to pass JSON arrays in MVC

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.