MVC前台Post/Get异步获得数据时参数的取值问题
2014-11-28 11:47
316 查看
Post方法,返回text,后台获得Data
View
Code
若需要返回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);
}
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);
}
相关文章推荐
- MVC中前台如何向后台传递数据------$.get(),$post(),$ajax(),$.getJSON()总结
- SpringMVC Controller接收前台ajax的GET或POST请求返回各种参数(转)
- MVC中前台如何向后台传递数据------$.get(),$post(),$ajax(),$.getJSON()总结
- socket模拟http中post或者get提交数据,并获得响应数据
- socket模拟http中post或者get提交数据,并获得响应数据
- Android -- 提交数据到服务器,Get Post方式, 异步Http框架提交
- PHP引号转义中解决POST,GET,Mysql数据自动转义问题
- [项目bug收集整理3]get页面,post页面的url 参数预防问题
- iOS 数据请求 同步get 同步post 异步get 异步post
- 参数传递中编码问题(Get/Post 方式)(一)
- php 分页显示数据 post参数传递问题解决方法
- 参数传递中的编码问题(get和post方式)
- [转载]jquery ajax/post/get 传参数给 mvc的action
- httpurlconnection post 和GET 分别传递2个参数给后台,返回JSON 解决乱码问题
- 参数传递中编码问题(Get/Post 方式)(三)
- PHP引号转义中解决POST,GET,Mysql数据自动转义问题
- Struts2 获得前台提交数据 乱码问题的解决
- Jquery和 LigerUI 用Post\Get\Ajax调用数据前台实例!
- Cocos2d—X游戏开发之LibCurl高级篇(get,post服务器数据)(网络详细参数信息)
- php 分页显示数据 post参数传递问题解决方法