Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use TempData to pass data ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 416
    Comment on it

    ASP.NET MVC TempData object is used to share data between controller actions.It is a dictionary object derived from TempDataDictionary. The value of TempData persists until it is read or until the current users session times out.TempdData can be used to maintain data between controller actions as well as between redirects.

    In the below code we illustrate how TempData can be used to pass data from one controller action to another.

    // We store a file object in (TemporaryFile)

     public ActionResult TemporaryFile()
    {
                    File file = new File
                    {
                            FileID = "112",
                            FileName = "Checklist",
                            FileType = "Excel"
                    };
                    TempData["File"] = file;
                    return RedirectToAction("PermanentFile");
    }

    //We retrieve a file object in (PermanentFile)

     public ActionResult PermanentFile()
    {
                   File file = TempData["File"] as File;
                   return View(file);
     }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: