jquery requests, which are serialized using json.stringify, and must be specified in the Transport format contenttype
$.ajax ({URL:'/api/sysuser?token= ' +token, type:' PUT ', data:JSON.stringify ({"UserID": ID,"UserName": $ (' #inputUserName '). Val (),"Cellphone": $ (' #inputCellPhone '). Val (),"Email": $ (' #inputEmail '). Val (),"Telephone": $ (' #inputTelePhone '). Val (),"ShowName": $ (' #inputShowName '). Val (),"Roleid": $ (' #selectRole '). Val ()}), ContentType:' Application/json ', DataType:"JSON", Success:function(Result) {varRe = eval (' (' + result + ') '); alert (re.message); $("#myModal"). Modal ("Hide"); Otable.fndraw (); }, Error:function(ERR) {alert ("Error"); } });
Background code, using Frombody to get parameter data
[Httppatch] [httpput] PublicCommon. Httpresult Update ([Frombody]models.sys_user sysuser) {common. Httpresult result=NewCommon. Httpresult (); Models.sys_user User=NewModels.sys_user (); User.userid=Sysuser.userid; User.username=Sysuser.username; User.cellphone=Sysuser.cellphone; User.email=Sysuser.email; User.roleid=Sysuser.roleid; User.showname=Sysuser.showname; User.telephone=Sysuser.telephone; BOOLRe =bll.sysUserManager.Update (user); if(re) {result.state=Common. ResultType.success.ToString (); Result.message=Lang.message.UPDATESUCCES; } Else{result.state=Common. ResultType.error.ToString (); Result.message=Lang.message.UPDATEFAIL; } returnresult; } #endregion
Reference blog: ASP. NET MVC Learning Series (ii)-WEBAPI request
ASP. NET MVC 5 WEB API put request