Search code examples
asp.netasp.net-mvc-3razorpost-redirect-get

Changing view vs Redirecting in ASP.net MVC3


There are several advantages of having doing a GET_POST_REDIRECT after an operation; however in absence of making a redirect, we return a View i.e. return a different view (after POST return an Index view).

In terms of web and pages what is the real thing going on when we return a different view from the action method (Returning index from POST). When can we use this and when it isn't recommended. What happens to the URL / URI?

If in case of single big/sophisticated page which requires several levels of processing should we redirect to same page again with error or returning the same view with error message, which one will be better or recommended?


Solution

  • You can return any ActionResult from action. You can return ViewResult for view with explicitly specified name (which differs from action name). Nothing happens with page URL in such case just a different HTMLs will be returned from the server for different views.

    Use redirect or return result directly - it depends on your actual case and web site design. There are no any concrete answer.