2

I am new in MVC 4 web development and i am creating a control panel. I have developed a Add user page and submit information in database successfully. But after submit when i press back button it will show previous form. i am using redirection the page to same page after submit form. here is the code to redirect

public ActionResult AdminPanel(RegisterUserModel user)
    {
        if (ModelState.IsValid) // Check the model state for any validation errors
        {       
            if (user.AddUserToDB(user.username, user.password, user.fullName,user.contactNo,user.COAId)) // Calls the Login class checkUser() for existence of the user in the database.
            {

                TempData["SuccessMessage"] = "User Added Sucessfully!";
                ModelState.Clear();
                return Redirect("AdminPanel");
            }
            else
            {
                ViewBag.SuccessMessage = "User Not Added";
                return View();
            }
        }

            SelectList clientsList = GetClinetList();

            ViewBag.clientsList = clientsList;



            return View(); // Return the same view with validation errors.

    }

I have tried many examples but issue not resolved yet so kindly give my suggesstions

Mudassar Shaheen
  • 1,397
  • 1
  • 9
  • 15

1 Answers1

0

If you don't want the user to be able to see the previous content when clicking back, then you must indicate that content should not be cached by the browser and must revalidate with the origin server

A summary of this behaviour is here - http://blog.55minutes.com/2011/10/how-to-defeat-the-browser-back-button-cache/

You could create a nocache attribute, like this one - https://stackoverflow.com/a/10011896/1538039, and apply it to your controller methods.

Community
  • 1
  • 1
Dylan Morley
  • 1,656
  • 12
  • 21