return Redirecttoaction ("Test"new {CW = CW, Firstdirectoryid = Firstdirectoryid});
The CW in the above is an object that receives the object CW in test, but Firstdirectoryid can receive it, after the parameters are passed in the formula.
The Redirecttoaction function allows a series of objects to be passed, but in practice it is found that these so-called objects are not real objects, and if the caller passes the object reference, the receiver gets null. In fact, redirecttoaction transfer uses the HTTP protocol, only value variables can be passed. If you need to pass objects, you can use TempData and session.
There is a property called TempData in the controllerbase of the ASP. Its type is tempdatadictionary, as the name implies is a dictionary class.
The role of tempdata in ASP. NET MVC is that it can be used to pass values between action execution procedures. Simply put, you can store the data in TempData when you execute an action.
Then the data in TempData can be used during the next action execution.
Such as:
1 public actionresult Index ()
2 {
3 this. tempdata["Mynane"] = "xiaoming";
4 return View ();
5}
6 Public ActionResult Index2 ()
7 {
8 String Myname=this. tempdata["Mynane"] as String;
9 return View ();
So it is necessary to pass the value type when jumping between actions, can be variable, reference type please use tempdata to pass.
ASP. MVC4 Jump Redirecttoaction parameter problem between action