首页 > 代码库 > MVC前台Post/Get异步获得数据时参数的取值问题
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 =http://www.mamicode.com/="False") { ShowFailTip(‘服务器繁忙,请稍候再试!‘); return; } else if (data =http://www.mamicode.com/="No") { ShowFailTip(‘您输入的优惠券不存在或已过期!‘); return; } else if (data =http://www.mamicode.com/="Used") { ShowFailTip(‘您输入的优惠券已使用!‘); return; } else if (data =http://www.mamicode.com/="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 = "http://www.mamicode.com/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前台Post/Get异步获得数据时参数的取值问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。