What's the difference in ASP.NET MVC of RedirectToRoute
and RedirectToAction
? It's not clear what the difference is to me.
RedirectToAction(String, Object) Redirects to the specified action using the action name and route values. RedirectToAction(String, String) Redirects to the specified action using the action name and controller name.
Return View doesn't make a new requests, it just renders the view without changing URLs in the browser's address bar. Return RedirectToAction makes a new request and the URL in the browser's address bar is updated with the generated URL by MVC.
When a Button is clicked, the Model object is populated with values and passed to the RedirectToAction method along with the name of the Controller and its Action method in ASP.Net MVC Razor. In this article I will explain with an example, how to redirect to Action method with Model data in ASP.Net MVC Razor.
The RedirectToAction() MethodThis method is used to redirect to specified action instead of rendering the HTML. In this case, the browser receives the redirect notification and make a new request for the specified action. This acts just like as Response. Redirect() in ASP.NET WebForm.
Redirect to route looks up the route table thats defined in global.asax and redirect to action redirects you to a specified controller/action.
that's about it really
RedirectToRoute means it redirects to a specific URL which is defined in routing API.(Global.asax)
RedirectToAction will return a http 302 response to the browser and then browser will make GET request to specified action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With