Sunday 31 December 2017

Using TempData in ASP.NET MVC.

ASP.Net MVC: TempData Tutorial with example
Description:

In this example we explain that how to use TempData in MVC.or implement functionality of the TempData in MVC Razor View.so here we demonstrate that what is TempData and use of the TempData in MVC Razor View.

Generally TempData is derived from the TempDataDictionary class and is used for the pass value from controller to view and from Controller to Controller in MVC.
Controller:

public class EmployeeController : Controller
    {

        // GET: First
        public ActionResult Index()
        {
            TempData["Message"] = "Hello this is the Example of the TempData!";
            return new RedirectResult(@"~\Second\");
        }
    }
Second Controller: 

    public class SecondController : Controller
    {
        // GET: Second
        public ActionResult Index()
        {
            return View();
        }
    }

View: 

<html>
<head>
  
    <title>ASP.Net MVC: TempData Tutorial with example</title>
</head>
<body>
    <div>
        @TempData["Message"];
    </div>
</body>
</html>


This entry was posted in :

0 comments:

Post a Comment