1. Good
ref: https://www.dotnettricks.com/learn/mvc/return-view-vs-return-redirecttoaction-vs-return-redirect-vs-return-redirecttoroute
ASP.NET MVC - View() vs RedirectToAction() vs Redirect() Methods
The Redirect() Method
This method is used to redirect to specified URL instead of rendering HTML. In this case, the browser receives the redirect notification and make a new request for the specified URL. This also acts like Response.Redirect() in Asp.Net WebForm. In this case, you have to specify the full URL to redirect.
Moreover, Redirect also cause the browser to receive a 302 redirect within your application, but you have to construct the URLs yourself.
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string Name)
{
ViewBag.Message = "Hi, Dot Net Tricks";
//Like Response.Redirect() in Asp.Net WebForm
return Redirect("Home/MyIndex");
}
public ActionResult MyIndex()
{
ViewBag.Msg = ViewBag.Message; // Assigned value : Null
return View("MyIndex");
############################################################################
############################################################################
2. How to redirect a request in ASP.NET Core MVC
沒有留言:
張貼留言