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")
-
5:55:33
MattMorseTV
7 hours ago $93.87 earned🔴Portland ANTIFA vs. ICE.🔴
146K295 -
3:13:00
Badlands Media
21 hours agoThe Narrative Ep. 40: Acceleratia.
51.6K13 -
LIVE
SpartakusLIVE
6 hours ago#1 Solo Spartan Sunday || TOXIC Comms, TACTICAL Wins, ENDLESS Content
909 watching -
49:45
Sarah Westall
5 hours agoComedians take Center Stage as World goes Nuts w/ Jimmy Dore
31.3K17 -
3:26:14
IsaiahLCarter
13 hours ago $5.88 earnedAntifa Gets WRECKED. || APOSTATE RADIO 030 (Guests: Joel W. Berry, Josie the Redheaded Libertarian)
43.2K1 -
LIVE
CassaiyanGaming
4 hours agoArena Breakout: Infinite Dawg
210 watching -
2:24:32
vivafrei
14 hours agoEp. 284: Ostrich Crisis Continues! Kirk Updates! Fed-Surrection Confirmed? Comey Indicted! AND MORE!
131K188 -
LIVE
Cewpins
4 hours agoSunday Sesh!🔥Rumble Giveaway Tonight!🍃420💨!MJ !giveaway
128 watching -
3:03:11
Conductor_Jackson
6 hours agoLet’s Play BioShock Infinite Burial at Sea Episode 2!
24.6K -
5:21:16
EricJohnPizzaArtist
6 days agoAwesome Sauce PIZZA ART LIVE Ep. #63: Charlie Sheen
54.7K4