Finished 'ViewData in ASP.NET MVC'

master
jason.zhu 2021-06-10 18:05:55 +10:00
parent 33c8722583
commit 2d19c8578d
2 changed files with 40 additions and 3 deletions

View File

@ -11,10 +11,14 @@ namespace FirstMVCDemo.Controllers
public class HomeController : Controller
{
// GET: Home
public ActionResult Index(int id)
public ActionResult Index()
{
EmployeeBusinessLayer employeeBL = new EmployeeBusinessLayer();
Employee employee = employeeBL.GetEmployeeDetails(id);
Employee employee = employeeBL.GetEmployeeDetails(102);
ViewData["Employee"] = employee;
ViewData["Header"] = "Employee Details";
return View();
}
}

View File

@ -8,9 +8,42 @@
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<title>Page Title</title>
</head>
<body>
@{
var employee = ViewData["Employee"]
as FirstMVCDemo.Models.Employee;
}
<h2>@ViewData["Header"]</h2>
<table style="font-family:Arial">
<tr>
<td>Employee ID:</td>
<td>@employee.EmployeeId</td>
</tr>
<tr>
<td>Name:</td>
<td>@employee.Name</td>
</tr>
<tr>
<td>Gender:</td>
<td>@employee.Gender</td>
</tr>
<tr>
<td>City:</td>
<td>@employee.City</td>
</tr>
<tr>
<td>Salary:</td>
<td>@employee.Salary</td>
</tr>
<tr>
<td>Address:</td>
<td>@employee.Address</td>
</tr>
</table>
<div>
<h1>Index View Coming From Views/Home Folder</h1>
</div>