My setup:
- Have a view for a route like:
/Pages/Details/2 - The page details view has
<% Html.RenderAction("CreatePageComment", "Comments"); %>to render a comment form - Comment form posts to
Comments/CreatePageComment /Comments/CreatePageCommentreturnsRedirectToActionwhen a comment is created successfully- This all works nicely
My question:
If there is a validation error, how should I return to /Pages/Detail/1 and show the error in the comment form?
- If I use
RedirectToAction, it seems validation is tricky; should I even be using the Post-Redirect-Get pattern for validation errors, instead of just returning? - If I return
View()it kicks me back to showing theCreateComment.aspxview (with validation, but just a form on a white page), not the/Pages/Details/2route that called theRenderAction.
If the PRG pattern should be used, then I think I just need to learn how to do validation while using PRG. If not — and to me this seems better handled by returning View() — then I don't know how to get the user returned to the initial view, showing the form errors, while using RenderAction.
This feels like the game where you tap your head and rub your belly at the same time. I wasn't good at that one either. I'm new at MVC, so that's likely the problem here.