When do you use View() vs. RedirectToAction

后端 未结 3 592
心在旅途
心在旅途 2021-02-18 14:38

This existing question sums up the basics of my question. The best answers there tells the difference between the two methods. I am looking for guidelines as to which method to

3条回答
  •  感动是毒
    2021-02-18 15:37

    1. Return View doesn't make a new requests, it just renders the view
    2. without changing URLs in the browser's address bar. Return
      RedirectToAction makes a new requests and URL in the browser's address bar is updated with the generated URL by MVC.
    3. Return Redirect also makes a new requests and URL in the browser's address bar is updated, but you have to specify the full URL to redirect
    4. Between RedirectToAction and Redirect, best practice is to use RedirectToAction for anything dealing with your application actions/controllers. If you use Redirect and provide the URL, you'll need to modify those URLs manually when you change the route table.
    5. RedirectToRoute redirects to the specifies route defined in the the Route table.

提交回复
热议问题