I have an ASP.NET MVC online shop-like application with two views:
- An item's page (photo, description, etc.)
- A form where the user may leave a review
After the user successfully submits the form, he should be redirected back to the item's page and a one-time message should be displayed on top: "Your review has been submitted successfully".
The controller code (simplified) looks like this:
[HttpGet]
public ActionResult ViewItem([Bind] long id)
{
var item = _context.Items.First(x => x.Id == id);
return View(item);
}
[HttpGet]
public ActionResult AddReview()
{
return View();
}
[HttpPost]
public ActionResult AddReview([Bind] long id, [Bind] string text)
{
_context.Reviews.Add(new Review { Id = id, Text = text });
_context.SaveChanges();
return RedirectToAction("ViewItem");
}
There are a few requirements to meet:
- The message must not show again if the user refreshes the item's page.
- The message must not pollute the URL.
- The controller methods may not be merged into one.
I was thinking of storing the message in user session and discarding it once displayed, but may be there's a better solution?