我正在处理一个项目,我有一些错误检查。但是,每次都要提交表单,所以我不得不中断提交。这是我做的。一旦错误检查破坏了表单就不会提交
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "order-form" }))
{
...
<input type="submit" name="[email protected](item.Id)" value="@T("Admin.Common.Save")" id="[email protected](item.Id)" class="adminButton" style="display: none;" onclick="SaveBtn(@item.Id);" />
...
var originalIssuedQty = 0;
function SaveBtn(id) {
var quantity = parseInt($("#pvQuantity" + id).val());
var issuedQty = parseInt($("#pvIssuedQty" + id).val());
var stockQty = parseInt($("#hfStockQty" + id).val());
var availableStockQty = stockQty + parseInt(originalIssuedQty);
//Issued Quantity cannot exceed Quantity (you can't issue more than requested)
if (issuedQty > quantity) {
alert("Issued Quantity cannot exceed Quantity.");
$("#order-form").submit(function (e) { e.preventDefault(); });
return false;
}
//Make sure Issued Quantity is within Available Stock Quantity
if (issuedQty > availableStockQty) {
alert("There is not enough Products in Stock to issue this amount.");
$("#order-form").submit(function (e) { e.preventDefault(); });
return false;
}
//Present confirmation
var result = confirm('@T("Admin.Common.AreYouSure")');
if (!result) {
$("#order-form").submit(function (e) { e.preventDefault(); });
return false;
}
else {
$("#order-form").submit(function (e) { this.submit(); });
//$("#order-form").submit(function (e) { return true; });
}
}
...
}
这是问题所在。每当我尝试提交第一次,而没有触发我的错误检查,事情就会起作用。当我触发错误检查时,事情就会起作用。但是,如果我修复错误并尝试再次提交,则页面仅会刷新。任何想法都是非常有帮助的。谢谢。
您是否尝试过使用Chrome开发人员工具或firefox上的firefox进行调试? – 2013-03-21 19:14:25
向我们显示您的表格html – Huangism 2013-03-21 19:23:38
我很希望我可以Fabio。不幸的是,由于我为之工作,我们只能使用IE8糟糕的开发工具。没有错误从我所见过的。 – IyaTaisho 2013-03-21 19:28:48