ASP. NET MVC 5 WEB API put request

Source: Internet
Author: User

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

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.