Referring to other people's articles, I try to write:
Data Source: Memberinroles
1 var memberinroles= {}; 2 for (var i=0;i<sureoptions.length;i++) {3 memberinroles["memberinroles[" +i+ "]. UserId "]=sureoptions[i].value; 4 memberinroles["memberinroles[" +i+ "]. Roleid "]=" @Model. Roleid "; 5 }
Controller Action
1 [HttpPost] 2 Public Jsonresult userselectsave (list<memberinrole> memberinroles)3 {4 return Json (new {data = 0, msg = "" }); 5 }
Try using $.ajax
1 $.ajax ({2Type: "POST",3DataType: "JSON",4URL: "@Url. Action (" Userselectsave "," rolemanager ", new {area =" DeskTop "})",5 data: {memberinroles:memberinroles},6Beforesend:function () { },7Completefunction () { },8Successfunction(data) {9 //Format ErrorTen if(!data| | (!data.status&&data.status!=0)){ OneAlertbox (Boxcallback, "0", "hint", "System parameter Error!") "); A return false; - } - //Success the if(Data.status = = "0") { - -}Else { -Alertbox (Boxcallback, "0", "hint", data.msg); + return false; - } + }, AErrorfunction(data) { atAlertbox (Boxcallback, "0", "hint", "system exception, please retry later"); - return false; - } -});
The result shows that the received parameter is null and continues to be modified:
$.ajax ({type:"POST", DataType:"JSON", URL:"@Url. Action (" Userselectsave "," rolemanager ", new {area =" DeskTop "})", data: {memberinroles}, Beforesend:function() {}, complete:function() {}, Success:function(data) {//Format Error if(!data| | (!data.status&&data.status!=0) {alertbox (Boxcallback,"0", "hint", "System parameter Error!" "); return false; } //Success if(Data.status = = "0") { } Else{alertbox (Boxcallback,"0", "hint", data.msg); return false; }}, Error:function(data) {Alertbox (Boxcallback,"0", "Prompt", "system exception, please retry later"); return false; }});
The results are reported directly to the yellow pages, the address of the scrub is the address before the submission, and I added an HD character before the name of my parameter.
For the "DXWorkFlow.Web.Areas.Desktop.Controllers.RoleManagerController" method "System.Web.Mvc.ActionResult
Usermanager (Int32, Int32, System.String, System.String) "cannot be null
The parameter "ParentID" of type "System.Int32", the parameter dictionary contains a null item. Optional parameter must be a reference type, can be null
The type or declaration as an optional parameter.
Parameter name:parameters
Look at the submission of others appear to have been submitted by $.post.
As a result, it is possible to use $.post, and I do not understand why.
1$.post ("@Url. Action ("Userselectsave", "RoleManager", new {area ="DeskTop" })",2 Memberinroles,3 function (data) {4 //Format Error5 if(!data| | (!data.status&&data.status!=0)){6Alertbox (Boxcallback,"0","Tips","System parameter Error! ");7 return false;8 }9 //SuccessTen if(Data.status = ="0") { One A}Else { -Alertbox (Boxcallback,"0","Tips", data.msg); - return false; the } - } -);
I really can't understand the difference between $.ajax and $.post way.
Please enlighten me if you know the specific information that $.ajax and $.post distinguish.
Reference article:
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/
Http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx
Http://www.cnblogs.com/birdwudi/archive/2010/08/26/1809511.html
How the ASP. NET MVC backend accepts the array list dictionary returned by the front end