ASP. MVC4 Jump Redirecttoaction parameter problem between action

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.