0

When i click submit button all values will saved on database,and the text box fields get cleared, when i use refresh the submit action will repeat and it will stores already exiting same values.How to solve this problem....

My code is

 [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);

                    }

Thanks in advance..

1
  • 1
    show your controller.... Commented Nov 4, 2013 at 10:36

1 Answer 1

2

Instead of return View(...), do return RedirectToAction(...). That way you can refresh the page as many times as you like.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks it will works...As the same way i am using partial view to bind data in webgrid
The ID value also get cleared so i unable to bind data depend upon ID
You should pass that ID in the redirect and load any data you need for displaying in that method instead of in the [HttpPost] method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.