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
Sports Wars
2 hours agoNFL Week 1 MADNESS, Phillies Karen Goes VIRAL, Angel Reese Suspended As WNBA Is DEAD
1,817 watching -
LIVE
LumpyPotatoX2
3 hours agoWelcome to The Finals [OPEN PARTY] - #RumbleGaming
2,480 watching -
13:05
Mike Rowe
1 day agoIs College DEAD? Inside America’s #1 Trade School | Sheree Utash From #448 | The Way I Heard It
5.52K6 -
LIVE
Times Now World
2 days agoWorld News LIVE | Maduro Dares Trump, Says China Is Now World’s Top Power Not US
172 watching -
1:39:58
Gary Cardone
2 hours ago $0.45 earnedLIVE With Gary Cardone
1.19K -
LIVE
Major League Fishing
3 days agoLIVE Tackle Warehouse Invitationals Championship, Day 3
179 watching -
2:15:06
Game On!
19 hours ago $20.32 earnedNFL Week 1 Wise Guy Round Table BEST BETS!
113K2 -
4:08:14
EXPBLESS
4 hours agoNew Game + On Elden Ring 🔥JOIN UP
8.17K -
12:11
Nikko Ortiz
1 day agoCrashout 6 Rumble
61K8 -
LIVE
Midnight In The Mountains
6 hours agoGaming w/ PER·SE·VER·ANCE | Sunday Funday Split Screen Gameplay BL3
109 watching