我正在更新MVC 4中网格内的文本框。该值已更新,但页面未刷新并重定向到IE 8中指定的actionresult。
控制器代码
public JsonResult UpdateCart(int Quantity, int ProductID)
{
if (System.Web.HttpContext.Current.Session["UserID"] != null)
{
objcartresponse.ProductID = ProductID;
objcartresponse.Quantity = Quantity;
objcart.UpdateCart(objcartresponse);
return Json(new
{
redirectUrl = Url.Action("ShoppingCart", "Cart"),
isRedirect = true
});
}
else
{
return Json(new
{
redirectUrl = Url.Action("Login", "Account"),
isRedirect = true
});
}
}
jQuery代码
$(document).ready(function () {
$(function () {
$('.edit-mode').hide();
$('.edit-user, .cancel-user').on('click', function () {
var tr = $(this).parents('tr:first');
tr.find('.edit-mode,.display-mode').toggle();
});
$('.save-TZ').on('click', function () {
var tr = $(this).parents('tr:first');
var id = $(this).attr('id');
var qty = tr.find("#Quantity").val();
tr.find('.edit-mode,.display-mode').toggle();
var Wishlist = { "Quantity": qty, "ProductID": id };
$.ajax({
url: '/Cart/UpdateCart/',
data: JSON.stringify(Wishlist),
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (json) {
if (json.isRedirect) {
window.location.href = json.redirectUrl;
}
}
});
});
});
});
我尝试将jquery中的 window.location.href 更改为 window.location 。但它也没有在IE 8中运行。但在其他浏览器如chrome& FF工作正常。任何使代码在IE 8中工作的建议??代码中是否有任何错误。