0

当我单击提交按钮时,所有值都将保存在数据库中,并且文本框字段被清除,当我使用刷新时,提交操作将重复并且它将存储已经退出的相同值。如何解决这个问题....

我的代码是

 [HttpPost]
        public ActionResult ReceiptMaster(Receipt model, string command)
        {
            Receipt Receipt = new Models.Receipt();
            ViewData["RE"] = model.Recepit_NO;
            ViewData["PAYMODE"] = model.Pay_Mode;
            ViewData["Credit"] = model.Credited;
            ViewData["CustName"] = model.Cust_Name;
            ViewData["Cust_ID"] = model.Cust_Id;
            if (command == "Sumbit")
            {
                int Id = 0;
                if (model.Pay_Mode == "C")
                {
                    model.ChequeNo = "";
                    model.Cheque_Date = ("1/1/1753 12:00:00 AM");
                    model.Bank_Name = "";
                    model.Bank_Address = "";
                }

                if (ModelState.IsValid)
                {
                    Id = Receipt.SaveReceipt(model.Id, model.Cust_Id, model.Pay_Amount, model.Pay_Mode, model.Bank_Name, model.Bank_Address, model.ChequeNo, model.Cheque_Date, model.Credited, model.Recepit_NO);
                    if (Id > 0)
                    {
                        /*RECEPIT NUMBER INCREMENT*/
                        string y = model.Recepit_NO;
                        int i = Convert.ToInt32(y.Substring(2));
                        i = i + 1;
                        string re = "RE" + i;
                        model.Recepit_NO = re;
                        ViewData["RE"] = re;

                        /*END RECEPIT NUMBER*/
                        ViewData["Success"] = "Product was saved successfully.";
                        ViewData["ControlView"] = 1;
                        ViewData["Success"] = "Product was saved successfully.";
                        ViewData["ControlView"] = 1;
                        ViewData["Cust_ID"] = "";
                        ViewData["Pay_mode"] = "C";
                        ViewData["Pay_Amount"] = "";
                        model.Pay_Amount= "";
                        model.Cheque_Date = "";
                        model.ChequeNo = "";
                        model.Bank_Name = "";
                        model.Bank_Address = "";
                        //ObservableCollection<Receipt> ReceiptList = new ObservableCollection<Receipt>();
                        model.ReceiptList = Receipt.GetReceiptList();// model.ReceiptList is your model property
                        ViewData["Count"] = model.ReceiptList.Count;
                        return View(model.ReceiptList);

                    }

提前致谢..

4

1 回答 1

2

而不是return View(...),做return RedirectToAction(...)。这样,您可以根据需要多次刷新页面。

于 2013-11-04T10:39:34.647 回答