【发布时间】:2016-09-09 12:39:03
【问题描述】:
我正在尝试从我的脚本中调用控制器操作,但没有调用该方法。
这是我的控制器操作:
[HttpPost]
public ActionResult EditQuantity(int? id, int quantity)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Cart cart = db.Carts.Find(id);
if (cart == null)
{
return HttpNotFound();
}
cart.Quantity = quantity;
db.SaveChanges();
string url = this.Request.UrlReferrer.AbsolutePath;
return Redirect(url);
}
这是我的脚本:
<script>
function refreshTotal(ProductId) {
var qty = document.getElementById("product-quantity-" + ProductId).value;
var UnitPrice = document.getElementById("unit-price-" + ProductId).innerText;
var total = qty * UnitPrice;
document.getElementById("product-total-" + ProductId).innerHTML = "$" + total.toFixed(2);
$.post('@Url.Action("EditQuantity", "Home")', { "id": ProductId, "quantity": qty }, function (data) {
});
}
</script>
从 HTML 调用脚本如下:
<td class=""><img src="" class="img-responsive" onclick="refreshTotal(@product.Id)"></td>
解决方案是在脚本中进行,从脚本调用没有被执行到操作。
【问题讨论】:
标签: javascript ajax asp.net-mvc controller