I am using the post-redirect-get pattern for all my forms, but now need to add AJAX functionality to improve the user experience. My initial thoughts are that the two do not mix.
In the PRG scenario, I would have my post action that would then either redirect back to my get action if there is a validation error, or redirect to my success get action otherwise.
In the AJAX scenario, I need to return a partial view either way. More typically, I would check to see if it is an AJAX request first. If so, return the partial view, else return the view.
Any thoughts or suggestions?
We use Post-Redirect-Get in our app. Here’s the essence of what we do, which hinges around the
Request.IsAjaxRequest()method and splitting your views into .aspx each of which host an .ascx so that each can action can be called both synchronously and asynchronously (i.e. via Ajax).We have a slight variant on this as well where we specifically catch
RulesException‘s (from the xVal in order to treat model validation errors differently to other ‘more serious’ exceptions.Saying all that though, sometimes I get a sneaking suspicion that we might be doing it slightly wrong.