ASP.NET Core MVC Interview Question #43
What is the difference between Redirect, RedirectToAction, and RedirectToRoute?
Controllers, Actions, Model Binding & Action Results Junior Beginner
Quick Interview Answer
Redirect sends the client to a specified URL. RedirectToAction generates a URL for an MVC controller/action, while RedirectToRoute generates a URL using a named route or route values.
Detailed Explanation
Redirect sends the client to a specified URL. RedirectToAction generates a URL for an MVC controller/action, while RedirectToRoute generates a URL using a named route or route values.
Prefer route-aware helpers such as RedirectToAction when redirecting within the MVC application because they reduce hard-coded URL dependencies.
Code Example
return Redirect("/products");
return RedirectToAction("Index", "Products");
return RedirectToRoute("product-details",
new { id = 10 });