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();
Employee employee = employeeBL.GetEmployeeDetails(101);
ViewBag.Employee = employee;
ViewBag.Header = "Employee Details";
return View();
return View(employee);
}
}
}

View File

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