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
TimcastIRL
2 hours agoJimmy Kimmel Show IN CHAOS Before Return, Affiliates REFUSE, Staff Says THEYLL QUIT
10,323 watching -
LIVE
Laura Loomer
2 hours agoEP145: Trump Makes BOMBSHELL Autism Announcement
844 watching -
LIVE
SpartakusLIVE
3 hours agoEXPLOSIVE 2v2 Tuesday has viewers GLUED to the screen
527 watching -
LIVE
GrimmHollywood
2 hours ago🔴LIVE • GRIMM'S TUESDAY FRIGHT NIGHT • STARRING GRIMM HOLLYWOOD • NO, I'M NOT HUMAN PART 1 •
98 watching -
LIVE
Flyover Conservatives
9 hours agoAI Encouraged Suicide: The Global Experiment on Our Kids - Joe Allen | FOC Show
285 watching -
1:07:40
Glenn Greenwald
4 hours agoTucker Carlson on Charlie Kirk Assassination Fallout, Free Speech, Foreign Policy, and the Reaction to his Kirk Remarks | SYSTEM UPDATE #520
135K100 -
14:22
Robbi On The Record
2 days ago $0.20 earnedGen Z’s Narcissism Obsession: Why Everyone’s a “Psychologist”
5.38K8 -
LIVE
GritsGG
5 hours agoQuad Win Streaks!🫡 Most Wins in WORLD! 3600+
156 watching -
1:09:28
Sarah Westall
2 hours agoCan the World Be This Strange? The Nature of Our Reality w/ Darius J Wright
7K -
megimu32
3 hours agoOn The Subject: Friends | 31 Years of the Sitcom That Defined a Generation
16.4K4