Premium Only Content

Part 9 Generate hyperlinks using actionlink html helper
In this video we will discuss, generating hyperlinks using actionlink html helper, for navigation between mvc pages.
Please watch Part 8, before proceeding.
We want to display all the employees in a bulletted list as shown below. Notice that all the employee names are rendered as hyperlinks.
Adding Links between pages using html helpers.png
When the hyperlink is clicked, the user will be redirected to employee details page, displaying the full details of the employee as shown below.
Generate links using Html.ActionLink html helper.png
Copy and paste the following Index() action method in EmployeeController class. This method retrieves the list of employees, which is then passed on to the view for rendering.
public ActionResult Index()
{
EmployeeContext employeeContext = new EmployeeContext();
// Replace square brackets with angular brackets
List[Employee] employees = employeeContext.Employees.ToList();
return View(employees);
}
At the moment, we don't have a view that can display the list of employees. To add the view
1. Right click on the Index() action method
2. Set
View name = Index
View engine = Razor
Select, Create a stronlgy-typed view checkbox
Select "Employee" from "Model class" dropdownlist
3. Click Add
At the point, "Index.cshtml" view should be generated. Copy and paste the following code in "Index.cshtml".
@* Replace square brackets with angular brackets *@
@model IEnumerable[MVCDemo.Models.Employee]
@using MVCDemo.Models;
[div style="font-family:Arial"]
@{
ViewBag.Title = "Employee List";
}
[h2]Employee List[/h2]
[ul]
@foreach (Employee employee in @Model)
{
[li]@Html.ActionLink(employee.Name, "Details", new { id = employee.EmployeeId })[/li]
}
[/ul]
[/div]
Points to Remember:
1. @model is set to IEnumerable[MVCDemo.Models.Employee]
2. We are using Html.ActionLink html helper to generate links
Copy and paste the following code in Details.cshtml
@Html.ActionLink("Back to List", "Index")
-
3:05:49
TimcastIRL
4 hours agoNew DOCS PROVE Obama Hillary CONSPIRACY To SABOTAGE Trump Admin | Timcast IRL
186K57 -
2:29:36
Laura Loomer
5 hours agoEP136: YOU'RE FIRED! White House Vetting Crisis Continues
18.2K11 -
8:07
MattMorseTV
5 hours ago $0.32 earnedTrump just LOWERED PRICES by 75 PERCENT.
12.8K24 -
LIVE
Misfit Electronic Gaming
7 hours ago $0.13 earned"LIVE" "Blind Descent' +"Dollhouse of Dead" Playtest 10 Followers till we hit 1000! We CAN do this!
209 watching -
21:53
Glenn Greenwald
7 hours agoMichael Tracey on the Street: What Do People Think of the Epstein Case?
107K54 -
2:26:28
megimu32
4 hours agoOTS: Board Games Gone Wild! The Loud, Weird & Chaotic Games That Raised Us
13.5K6 -
4:25:16
DamnDanieI
4 hours agoKill First, Loot Later – OTG Live
36.9K1 -
56:41
Donald Trump Jr.
8 hours agoLies, Leaks, and Lawfare: Censorship Corruption Exposed | TRIGGERED Ep.263
140K121 -
1:19:46
Precision Rifle Network
5 hours agoS4E25 Guns & Grub - Rex Is Back, I shot the 6.5PRC finally...
11.6K1 -
LIVE
rhywyn
3 hours agoうつ
23 watching