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")
-
LIVE
Kim Iversen
1 hour ago"Canada's Trump" Is Trudeau’s Worst Nightmare: Is Maxime Bernier the Future of Canada?
1,485 watching -
DVR
Bannons War Room
10 days agoWarRoom Live
2.58M435 -
16:06
The Rubin Report
7 hours agoProof the Islamist Threat in England Can No Longer Be Ignored | Winston Marshall
34.3K24 -
2:07:07
Robert Gouveia
4 hours agoFBI Files Coverup! Bondi FURIOUS; SCOTUS Stops Judge; Special Counsel; FBI Does
40.5K31 -
56:15
Candace Show Podcast
5 hours agoBREAKING: My FIRST Prison Phone Call With Harvey Weinstein | Candace Ep 153
107K66 -
LIVE
megimu32
1 hour agoON THE SUBJECT: The Epstein List & Disney Channel Original Movies Nostalgia!!
185 watching -
9:06
Colion Noir
10 hours agoKid With Gun Shoots & Kills 2 Armed Robbers During Home Invasion
16.9K3 -
54:28
LFA TV
1 day agoUnjust Man | TRUMPET DAILY 2.27.25 7PM
19.7K2 -
DVR
CatfishedOnline
7 hours ago $1.19 earnedGoing Live With Allen Weekly Recap
21.8K -
20:10
CartierFamily
7 hours agoAndrew Schulz DESTROYS Charlamagne’s WOKE Meltdown on DOGE & Elon Musk!
36.8K45