Finished 'ViewBag in ASP.NET MVC'

master
jason.zhu 2021-06-10 22:09:39 +10:00
parent 07956d2d3c
commit a875b59057
2 changed files with 5 additions and 6 deletions

View File

@ -14,10 +14,10 @@ namespace FirstMVCDemo.Controllers
public ActionResult Index() public ActionResult Index()
{ {
EmployeeBusinessLayer employeeBL = new EmployeeBusinessLayer(); EmployeeBusinessLayer employeeBL = new EmployeeBusinessLayer();
Employee employee = employeeBL.GetEmployeeDetails(102); Employee employee = employeeBL.GetEmployeeDetails(101);
ViewData["Employee"] = employee; ViewBag.Employee = employee;
ViewData["Header"] = "Employee Details"; ViewBag.Header = "Employee Details";
return View(); return View();
} }

View File

@ -12,11 +12,10 @@
</head> </head>
<body> <body>
@{ @{
var employee = ViewData["Employee"] var employee = ViewBag.Employee;
as FirstMVCDemo.Models.Employee;
} }
<h2>@ViewData["Header"]</h2> <h2>@ViewBag.Header</h2>
<table style="font-family:Arial"> <table style="font-family:Arial">
<tr> <tr>
<td>Employee ID:</td> <td>Employee ID:</td>