The previous action method can return a view with a view that renders a non-default action method named name, in which case it can be redirected to the action method that renders the view instead of rendering the view by itself.
It's a little cumbersome to understand.
returnView (" Nice");//You can use ==>returnRedirecttoaction (" Nice"), orreturnView (" Nice","Good");==>returnRedirecttoaction (" Nice","Good"); The result is the same unless there are some data in Nice's action that need to be passed to Nice view
For this redirect, I still have some not quite understand "temporary redirect" and "permanent redirect" Redirecttoactionpermanent
I have to say that MVC's controller helper method is really a lot, a redirect incredibly divided into
1.redirecttoroute//directed to the routing system URL
2.redirecttoaction//directed to the action method
In fact, these two helper methods do the same thing, is to redirect the current route to another action method, and then go to render a view back to the user.
But now the problem is, if it is redirected, the browser will submit a new HTTP request, which means that we are going to the original request details of the method, meaning we can not access the data in this action method, if we want to save the redirect before
What to do with the data in the action method, then we can use the TempData feature, which is often magical, and unlike a global variable, application shutdown is released, it is marked for deletion after the first read, and then formally deleted after the request is processed. is not very nice, do not occupy much memory, but also can pass data across requests, but also can automatically clear the memory ~ ~ ~
Use the following method
?
| 1 2 3 4 5 6 7 8 9 10 |
public RedirectToRouteResult Index(){ TempDate["Nice"] = "Terry"; TempData["Reason"] = "中奖啦"; return RedirectToAction("Nice"); }public ViewResult Nice(){ Nice nice = new Nice{Name=TempData["Nice"],Reason=TempData["Reason"]}; return View(nice); } |
If you don't want to let go of this cross-domain data for more than one, you can use
Tempdata.keep ("nice");
So your nice data can be retained again, the next time you read, the request will be completed or deleted, if you still do not want to be deleted, then I can only recommend you use the session ...