Asp.net mvc 4 MVC 4 ActionResult第二轮未命中

Asp.net mvc 4 MVC 4 ActionResult第二轮未命中,asp.net-mvc-4,refresh,actionresult,Asp.net Mvc 4,Refresh,Actionresult,我们有一个显示数据行的索引页。当我们去编辑一行时,会点击edit ActionResult并显示数据供我们编辑。然后,当我们去提交更改时,HttpPost ActionResult被点击,数据被保存 我们可以返回到索引页并查看保存的更改,但是如果我们再次尝试编辑数据,则不会触发edit ActionResult,并且会显示旧数据,直到我们点击F5,然后触发edit ActionResult并刷新dat 我们如何确保每次都点击编辑操作结果,而不必进行硬刷新 谢谢 以下是控制器上的编辑操作结果:

我们有一个显示数据行的索引页。当我们去编辑一行时,会点击edit ActionResult并显示数据供我们编辑。然后,当我们去提交更改时,HttpPost ActionResult被点击,数据被保存

我们可以返回到索引页并查看保存的更改,但是如果我们再次尝试编辑数据,则不会触发edit ActionResult,并且会显示旧数据,直到我们点击F5,然后触发edit ActionResult并刷新dat

我们如何确保每次都点击编辑操作结果,而不必进行硬刷新

谢谢

以下是控制器上的编辑操作结果:

    [CustomAuthorizePDG]
    public ActionResult Edit(int id = 0)
    {
        var model = this._db.ProductApprovals_ProductApproval.Find(id);
        if (model == null) {
            return HttpNotFound();
        }
        var spServer = ConfigurationManager.ConnectionStrings["SPServer"].ConnectionString;
        ViewBag.ProductStatusId = new SelectList(this._db.ProductApprovals_ProductStatus, "ProductStatusId", "ProductStatus", model.ProductStatusId);
        return View(model);
    }
然后是HttpPost结果:

    [CustomAuthorizePDG]
    [HttpPost]
    [ValidateAntiForgeryToken]
    [ErrorHandler]
    public ActionResult Edit(ProductApprovals_ProductApproval model, HttpPostedFileBase file)
    {
        if (ModelState.IsValid) {
                if (file != null && file.ContentLength > 0) {
                    var sp = new ProductApprovalDataContext(new Uri("http://sp-appcentral-int/ProductApproval/_vti_bin/ListData.svc"))
                    {
                        Credentials = CredentialCache.DefaultNetworkCredentials
                    };

                    var productApprovalForm = sp.ProductApprovalForm.Where(x => x.ProductApprovalId == model.ProductApprovalId.ToString(CultureInfo.InvariantCulture)).FirstOrDefault();

                    if (productApprovalForm != null) {
                        var fileName = Path.GetFileName(file.FileName);
                        var extension = Path.GetExtension(file.FileName);
                        var name = string.Format("{0}{1}", model.ProductApprovalId, extension);
                        var path = string.Format("/ProductApproval/Product Approval Form/{0}", name);
                        var contentType = extension == "docx" ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/msword";

                        productApprovalForm.CheckedOutTo = new UserInformationListItem
                        {
                            UserName = User.Identity.Name
                        };
                        productApprovalForm.Title = fileName;
                        sp.SetSaveStream(productApprovalForm, file.InputStream, false, contentType, path);
                        sp.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);

                        this.UpdateProductApprovalWithDocument(model, path, fileName);
                    }
                }

                this._db.Entry(model).State = EntityState.Modified;
                this._db.SaveChanges();

            return RedirectToAction("Index");
        }

        ViewBag.ProductStatusId = new SelectList(this._db.ProductApprovals_ProductStatus, "ProductStatusId", "ProductStatus", model.ProductStatusId);

        return View(model);
    }

因此,当触发HttpPost编辑时,它会成功地保存更改,并将其显示在索引视图中。如果随后返回到编辑操作结果,则会显示初始值,直到执行刷新。我们在代码上设置了一个断点,第二轮编辑操作结果不会被触发,直到您在HttpPost编辑操作中点击F5…

,请确保您正在执行重定向操作返回到索引操作。从问题描述中可以看出,如果您正在显示“编辑”操作中的“保存编辑”视图。您需要重定向回索引操作


如果仍然不起作用,请检查索引视图的HTML源代码,确保编辑URL仍然引用编辑操作方法。

代码在哪里?我想没有代码谁也帮不了你。。。