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")
-
14:31
Adam Does Movies
12 hours ago $1.41 earnedAlien: Earth Episode 5 - Recrap
20.7K1 -
12:54
Michael Button
16 hours ago $0.63 earnedWhat If We’re Just the Most Recent Civilization?
1.78K4 -
25:26
World2Briggs
17 hours ago $0.63 earnedTop 15 Most Visited Cities in the World
3.88K -
LIVE
BEK TV
22 hours agoTrent Loos in the Morning - 9/05/2025
277 watching -
LIVE
The Bubba Army
21 hours agoTyson vs Mayweather SUPERFIGHT! - Bubba the Love Sponge® Show | 9/05/25
4,004 watching -
LIVE
FyrBorne
1 hour ago🔴Warzone M&K Sniping: This May Be The Most Broken Update Yet
87 watching -
10:59
Degenerate Jay
15 hours ago $1.45 earned007 First Light Is The James Bond Game Fans Deserve
19K2 -
9:11
Faith Frontline
14 hours agoTucker Carlson SHOCKED As Cliffe Knechtle Reveals God’s Chosen People
6.81K4 -
23:10
Jasmin Laine
16 hours agoCTV Host Visibly UNCOMFORTABLE As Guest Calls Canadians RACIST—Poilievre Leaves Them SPEECHLESS
12K4 -
20:18
Fit'n Fire
16 hours ago $0.29 earned*NEW* CZ P10C OR Ported -- First 500 Rounds
7.32K1