
Lucky for us, there's a data structure called TempData. We need a way to save the model state somewhere that we can access it later. Here's the problem: those validation messages and input values are stored in the ModelState, which gets recreated when moving between actions. But if we try this in a naive solution, where instead of returning the View(model) when validation fails we just redirect back to the GET action, the validation messages and input values will not appear. PRG says that all POSTS need to redirect to a GET action, which sounds easy enough.

Let's get rid of that warning dialog using PRG. If we immediately click Save, our validation fires:īut what happens if we refresh the page? We get the validation warning: With each of these components implemented, when we run our sample app the rendered page looks like this: Public ActionResult Normal(AddUserVM model)įinally, we need the Home/Normal.cshtml view: Īdd a User => => => => => => => => => x.DateOfBirth) We will also need a HomeController controller with a Normal() action: public class HomeController : Controller First, we will build a view model class AddUserVM: public class AddUserVM Here's the code files we'll use for a regular POST scenario.

This pattern is meant to provide a more intuitive interface for users, specifically by reducing the number of duplicate form submissions. POST-REDIRECT-GET is a pattern that says a POST action should always REDIRECT to a GET action. Let's see what that pattern is, and how we can implement it in a simple ASP.NET MVC application. There's a pattern we can implement, called POST-REDIRECT-GET or PRG, that will eliminate these dialogs. I'm a fan of getting rid of anything that interferes with the user experience, and these dialogs certainly get in the way.

Anybody that's been on the internet for more than five seconds has encountered one of these:
