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:43
ABGTutorials
1 year agoLearning to use Hyperlinks in HTML
1 -
4:44
AGBLE
5 months agoHow To Create Hyperlink Using Figma
38 -
4:35
TECHNOLOGY, TIPS AND TRICK VIDEOS
9 months agoHow to Create a Hyperlink in Excel
7 -
7:13
SoftwareVid
6 months agoAdvanced Links | XHTML Tutorial
3 -
2:45
RestorationIsNow
2 years ago $0.02 earnedCreate a doTERRA Link Generator
43 -
0:30
henrykiyuri
1 year agoI will build SEO backlinks with high quality contextual link building
9 -
22:18
Relative Digital Marketing
3 years agoHow To Build Backlinks: 11 Link Building Strategies for 2021
289 -
6:55
SoftwareVid
6 months agoBeginning Links | XHTML Tutorial
3 -
2:30
ComputerScienceVideos
6 months agoProgramming In HTML5 - Tutorial 6 | Basic Links
3 -
2:19
thecreativeway
2 years agoAdding hyperlinks to an Adobe Indesign file
23