Description:
Controller:
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.
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>
0 comments:
Post a Comment