MVC前台Post/Get异步获得数据时参数的取值问题

Post方法,返回text,后台获得Data

View

        $.ajax({
                    type: "POST",
                    dataType: "text",//返回类型为文本
                    url:"/Order/AjaxGetCoupon?ids="+id,
                    data: { ConponCode: code, TotalPrice: totalPrice },
                    success: function (data) {
                        if (data == "False") {
                            ShowFailTip(‘服务器繁忙,请稍候再试!‘);
                            return;
                        }
                        else if (data == "No") {
                            ShowFailTip(‘您输入的优惠券不存在或已过期!‘);
                            return;
                        } else if (data == "Used") {
                            ShowFailTip(‘您输入的优惠券已使用!‘);
                            return;
                        } else if (data == "Limit") {
                            ShowFailTip(‘您输入的优惠券不满足最低消费金额!‘);
                            return;
                        } else {
                            $("#couponPriceId").text("¥" + data.split("|")[0]);
                            $("#payPriceId").text("¥" + data.split("|")[1]);
                        }
                    }
                });

Code

[HttpPost]       
public ActionResult AjaxGetCoupon(FormCollection Fm,int ids) {//ids为url中的参数或后台获得URL后的参数 Request.QueryString["ids"] if (string.IsNullOrWhiteSpace(Fm["ConponCode"])) { return base.Content("False"); } string couponCode = Fm["ConponCode"]; decimal num = Globals.SafeDecimal(Fm["TotalPrice"], (decimal) 0M); BLL.CouponInfo info = new BLL.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 = new ShoppingCartHelper(base.currentUser.UserID).GetShoppingCart4Selected(); switch (info.GetUseStatus(cartInfo, couponInfo)) { case 0: return base.Content("No"); case 1: { string str2 = (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"); }

若需要返回json则将 $.ajax 中 dataType: "json"

后台:public JsonResult AjaxGetCoupon(FormCollection Fm,int ids){

  return Json(new { errCode =0,message= "非常抱歉" });

}

 

页面传参

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);
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。