Search code examples
htmlasp.net-mvcasp.net-mvc-3query-stringtempdata

How to avoid a query string parameter being remembered?


I'm developing a messaging system on a website.

When user sends a message, she is redirected to inbox?status=sent which displays a neat status Message sent.

However, if she then goes on to see any of the inbox messages and clicks Back, she is brought to this statusful page again, whereas I don't want to display it anymore.

What is the standard way to handle this?


Solution

  • You could try using TempData

    [HttpPost]
    public ActionResult SendMessage()
    {
        // TODO: send the message
    
        TempData["status"] = "sent";
        return RedirectToAction("Result");
    }
    

    and in the Result view you could show the message by fetching it from TempData:

    <div>@TempData["status"]</div>