清除 ASP.net 中的按钮名称参数

Clear Button Name Parameter in ASP.net

您好,我是 ASP 和 MVC3 的新手,我的问题是如何清除 Post 中的按钮名称参数,因为每次单击带有按钮参数的按钮后我都会刷新页面,我上次单击的按钮的值仍然存在,在提交后或在 Controller 中刷新页面时或使用 Jquery 时,有什么方法可以清除这个东西吗?

谢谢

这是我的代码片段:

[HttpPost]
    public ActionResult HistoryPage(HistoryModel model, string btnAction)
    {
        if (Session["HistoryId"] != null)
        {
            switch (btnAction)
            {
                case "Delete History":
                    DeleteHistory(model, ref deleteHistoryError, ref deleteHistorySucesss);
                    break;
                case "AddHistory":
                    AddHistory(model);
                    break;

            }
        }
        return View(model);
    }

这里是删除历史

private static void DeleteHistory(HistoryModel model, ref string ErrorMessage, ref string SuccessMessage)
        {

                    foreach (var item in model.HistoryIds)
                    {
                        if (item != "")
                        {
                            bool result = Int32.TryParse(item, out HistoryIds);
                            if (result)
                            {
                                var History= db.History.Find(HistoryId);
                                bool HistoryExist = true;

                                if (History.HistoryId != null)
                                {

                                    History.LogicalDelete = true;
                                    History.DateModified = DateTime.Now;
                                    db.SaveChanges();


                                    SuccessMessage = "History  successfully deleted";
                                }
                                else 
                                {
                                    ErrorMessage = "Unable to delete History.";
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(ErrorMessage))
                    {
                        SuccessMessage = String.Empty;
                    }
                }
            }
        }

我的表单下方的 Cshtml 按钮

<input type="submit" name="btnAction" class="btnMultiDelete button_example button_example_small div-bottom-3 w100Percent txtAlignLeft"
                                value="Delete History" id="btnDeleteHistory" />

在浏览器刷新时(单击 F5),浏览器发出最后一次发出的请求(在您的情况下是 post)。这是浏览器的默认行为。

所以我们必须在这里遵循 PRG 模式。 PRG-POST-REDIRECT-GET。所以在你的代码中,你必须 return RedirectToAction("Get Action Name") 而不是返回视图。在这种情况下,浏览器的最后一个请求将是 GET,当您进行后续刷新时,它将发出 GET 请求而不是 POST

你的代码应该是这样的 -

    [HttpPost]
    public ActionResult HistoryPage(HistoryModel model, string btnAction)
    {
        if (Session["HistoryId"] != null)
        {
            switch (btnAction)
            {
                case "Delete History":
                    DeleteHistory(model, ref deleteHistoryError, ref deleteHistorySucesss);
                    break;
                case "AddHistory":
                    AddHistory(model);
                    break;
            }
            return RedirectToAction("Get Action Name ...");
        }
        return View(model);
    }