Finished 'Strongly Typed View in ASP.NET MVC'

This commit is contained in:
jason.zhu 2021-06-11 14:19:06 +10:00
parent a875b59057
commit 74036dd9de
2 changed files with 8 additions and 12 deletions

View File

@ -16,10 +16,9 @@ namespace FirstMVCDemo.Controllers
EmployeeBusinessLayer employeeBL = new EmployeeBusinessLayer(); EmployeeBusinessLayer employeeBL = new EmployeeBusinessLayer();
Employee employee = employeeBL.GetEmployeeDetails(101); Employee employee = employeeBL.GetEmployeeDetails(101);
ViewBag.Employee = employee;
ViewBag.Header = "Employee Details"; ViewBag.Header = "Employee Details";
return View(); return View(employee);
} }
} }
} }

View File

@ -2,7 +2,7 @@
@{ @{
Layout = null; Layout = null;
} }
@model FirstMVCDemo.Models.Employee
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -11,35 +11,32 @@
<title>Page Title</title> <title>Page Title</title>
</head> </head>
<body> <body>
@{
var employee = ViewBag.Employee;
}
<h2>@ViewBag.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>
<td>@employee.EmployeeId</td> <td>@Model.EmployeeId</td>
</tr> </tr>
<tr> <tr>
<td>Name:</td> <td>Name:</td>
<td>@employee.Name</td> <td>@Model.Name</td>
</tr> </tr>
<tr> <tr>
<td>Gender:</td> <td>Gender:</td>
<td>@employee.Gender</td> <td>@Model.Gender</td>
</tr> </tr>
<tr> <tr>
<td>City:</td> <td>City:</td>
<td>@employee.City</td> <td>@Model.City</td>
</tr> </tr>
<tr> <tr>
<td>Salary:</td> <td>Salary:</td>
<td>@employee.Salary</td> <td>@Model.Salary</td>
</tr> </tr>
<tr> <tr>
<td>Address:</td> <td>Address:</td>
<td>@employee.Address</td> <td>@Model.Address</td>
</tr> </tr>
</table> </table>
</body> </body>