Created
November 22, 2015 12:08
-
-
Save Tesla9527/31e257b45ed9eab55ab0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------- | |
Below is code in EmployeeController.cs | |
----------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using WebApplication2.Models; | |
namespace WebApplication2.Controllers | |
{ | |
public class EmployeeController : Controller | |
{ | |
public ActionResult Index() | |
{ | |
EmployeeContext employeeContext = new EmployeeContext(); | |
List<Employee> employees = employeeContext.Employees.ToList(); | |
return View(employees); | |
} | |
public ActionResult Details(int id) | |
{ | |
EmployeeContext employeeContext = new EmployeeContext(); | |
Employee employee = employeeContext.Employees.Single(emp => emp.EmployeeId == id); | |
return View(employee); | |
} | |
} | |
} | |
----------------------------- | |
Below is code in index.cshtml | |
----------------------------- | |
@model IEnumerable<WebApplication2.Models.Employee> | |
@using WebApplication2.Models; | |
@{ | |
ViewBag.Title = "Employee list"; | |
} | |
<div> | |
<h2>Employee list</h2> | |
<ul> | |
@foreach (Employee employee in Model) | |
{ | |
<li> | |
@Html.ActionLink(employee.Name, "Details", new { id = employee.EmployeeId }) | |
</li> | |
} | |
</ul> | |
</div> | |
----------------------------- | |
Below is code in Details.cshtml | |
----------------------------- | |
@model WebApplication2.Models.Employee | |
@{ | |
ViewBag.Title = "Employee Details"; | |
} | |
<h2>Employee Details</h2> | |
<table style="font-family:Arial"> | |
<tr> | |
<td> | |
<b>Employee Id:</b> | |
</td> | |
<td> | |
@Model.EmployeeId | |
</td> | |
</tr> | |
<tr> | |
<td> | |
<b>Name:</b> | |
</td> | |
<td> | |
@Model.Name | |
</td> | |
</tr> | |
<tr> | |
<td> | |
<b>Gender:</b> | |
</td> | |
<td> | |
@Model.Gender | |
</td> | |
</tr> | |
<tr> | |
<td> | |
<b>City:</b> | |
</td> | |
<td> | |
@Model.City | |
</td> | |
</tr> | |
</table> | |
@Html.ActionLink("Back to the details","Index") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment