MVC foreground Post/get parameter value problem when getting data asynchronously

Source: Internet
Author: User

Post method, return text, background to get data

View

        $.ajax ({type: "POST", DataType: "Text",//return type is a text URL: "/O Rder/ajaxgetcoupon?ids= "+id, data: {Conponcode:code, totalprice:totalprice}, suc Cess:function (data) {if (data = = "False") {showfailtip (' Server busy, please wait and try again!                            ‘);                        Return } else if (data = = "No") {Showfailtip (' the coupon you entered does not exist or has expired!                            ‘);                        Return } else if (data = = "used") {Showfailtip (' The coupon you entered has been used!                            ‘);                        Return } else if (data = = "Limit") {Showfailtip (' the coupon you entered does not meet the minimum spending amount!                            ‘);                        Return } else {$ ("#couponPriceId"). Text ("¥" + data.split ("|")                           [0]); $ ("#payPriceId"). Text ("¥" + data.split ("|")                        [1]); }                    }                });

Code

[HttpPost]       
Publicactionresult ajaxgetcoupon (formcollection fm,int IDs) {//ids for parameters in URL or backend for URL parameters request.querystring["IDs"] if(string. Isnullorwhitespace (fm["Conponcode"])) { return Base. Content ("False"); } stringCouponcode = fm["Conponcode"]; decimalnum = Globals.safedecimal (fm["Totalprice"], (decimal) 0M); Bll. Couponinfo Info=NewBLL. Couponinfo (); Model.couponinfo Couponinfo= info. Getcouponinfo (Couponcode,false); if(Couponinfo! =NULL) { if(Couponinfo.status = =2) { return Base. Content ("used"); } if(Couponinfo.limitprice >=num) { return Base. Content ("Limit"); } shoppingcartinfo Cartinfo=NewShoppingcarthelper (Base. Currentuser.userid). Getshoppingcart4selected (); Switch(info.) Getusestatus (Cartinfo, Couponinfo)) { Case 0: return Base. Content ("No"); Case 1: { stringSTR2 = (num-couponinfo.couponprice). ToString ("F"); return Base. Content (CouponInfo.CouponPrice.ToString ("F") +"|"+str2); } Case 2: return Base. Content ("used"); Case 3: return Base. Content ("Limit"); Case 4: return Base. Content ("Categorylimit"); Case 5: return Base. Content ("Productlimit"); Case 6: return Base. Content ("Skulimit"); Case 7: return Base. Content ("Categoryno"); Case 8: return Base. Content ("Productno"); Case 9: return Base. Content ("Skuno"); } } return Base. Content ("No"); }

If you need to return JSON, you will $.ajax in DataType: "JSON"

Backstage: Public Jsonresult ajaxgetcoupon (formcollection fm,int IDs) {

Return Json (New {Errcode =0,message= "very sorry"});

}

Page Pass Parameter

Location.href = "order/submitorder?sku=" + SKU + "&g=" + Groupbuyid;

Public ActionResult SubmitOrder (string sku, int count = 1, int c = 0, int g = 0, String viewName = "SubmitOrder")
{

Shoppingcartinfo cartinfo = new Shoppingcartinfo ();

Return base. View (ViewName, cartinfo);
}

MVC foreground Post/get parameter value problem when getting data asynchronously

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.