From 74036dd9de7d62894db7b183f0e9dd5d5ad28644 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Fri, 11 Jun 2021 14:19:06 +1000 Subject: [PATCH] Finished 'Strongly Typed View in ASP.NET MVC' --- FirstMVCDemo/Controllers/HomeController.cs | 3 +-- FirstMVCDemo/Views/Home/Index.cshtml | 17 +++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/FirstMVCDemo/Controllers/HomeController.cs b/FirstMVCDemo/Controllers/HomeController.cs index 768459d..a0f58ae 100644 --- a/FirstMVCDemo/Controllers/HomeController.cs +++ b/FirstMVCDemo/Controllers/HomeController.cs @@ -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); } } } \ No newline at end of file diff --git a/FirstMVCDemo/Views/Home/Index.cshtml b/FirstMVCDemo/Views/Home/Index.cshtml index f8c421f..d9d0d8a 100644 --- a/FirstMVCDemo/Views/Home/Index.cshtml +++ b/FirstMVCDemo/Views/Home/Index.cshtml @@ -2,7 +2,7 @@ @{ Layout = null; } - +@model FirstMVCDemo.Models.Employee @@ -11,35 +11,32 @@ Page Title - @{ - var employee = ViewBag.Employee; - }

@ViewBag.Header

- + - + - + - + - + - +
Employee ID:@employee.EmployeeId@Model.EmployeeId
Name:@employee.Name@Model.Name
Gender:@employee.Gender@Model.Gender
City:@employee.City@Model.City
Salary:@employee.Salary@Model.Salary
Address:@employee.Address@Model.Address