用jQuery页面发布后不重定向

时间:2017-07-01 14:21:36

标签: jquery asp.net asp.net-mvc redirect post

我使用jQuery来POST我的表单到控制器和控制器函数总是在return RedirectToAction("Index")但它没有重定向。

我的jQuery代码:

<script type="text/javascript">
    $("form").on("submit", function (e) {
        e.preventDefault();
        if ($('form').valid()) {
            var f = $("form");
            var dialog = bootbox.dialog({
                message: '<p><i class="fa fa-spinner fa-spin"></i> Proszę czekać...</p>',
                size: 'small',
                closeButton: false
            });       
            $.post(f.action, f.serialize(), function (result) {
                console.log(result);
                dialog.modal('hide');                    
            });
            return false;
        }
    });
</script>

我的示例控制器功能代码:

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            InvoiceTransfer invoiceTransfer = db.InvoiceTransfers.Find(id);
            int pwID = Convert.ToInt32(System.Web.HttpContext.Current.Session["PaintballWorkerID"]);
            if (invoiceTransfer.FromID != pwID)
            {
                return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
            }
            for (int i = 0; i < invoiceTransfer.Invoices.Count; i++)
            {
                db.InvoiceTransfers.Include("Invoices").FirstOrDefault(z => z.InvoiceTransferID == id).Invoices.Remove(invoiceTransfer.Invoices[i]);
            }
            db.InvoiceTransfers.Remove(invoiceTransfer);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

它总是在函数末尾转到Index,但浏览器没有重定向。正如您所看到的,我使用console.log(result)并且在控制台result中始终是我的索引页面的html代码。

0 个答案:

没有答案