1

I'm showing a small table with a list of usernames, and I want an ActionLink next to each username to Edit the user on another page.

Here's my view page:

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<WebUI.Models.IndexModel>>" %> <table> <tr> <th></th> <th>Username</th> </tr> <% foreach (var item in Model) { %> <tr> <td><% Html.ActionLink("Edit", "Edit", "Employee", new { id = item.UserID }, null); %></td> <td><%: item.Username %></td> </tr> <% } %> </table> 

My controller methods in EmployeeController:

public ActionResult Index() { List<IndexModel> model = new List<IndexModel>(); //load model with data return View(model); } public ActionResult Edit(Guid id) { return View(); } 

My model:

public class IndexModel { public Guid UserID { get; set; } public string Username { get; set; } } 

The usernames display correctly, just the link doesn't show up. I'm not sure why it wouldn't throw an error instead.

What am I missing here?

2 Answers 2

4

You are missing a : in your code. Try this:

<td><%: Html.ActionLink("Edit", "Edit", "Employee", new { id = item.UserID }, null) %></td> 

EDIT: Removed the ; at the end didn't notice it earlier.

Sign up to request clarification or add additional context in comments.

Comments

2

try removing the ; and adding : before-

<%:Html.ActionLink("Edit", "Edit", "Employee", new { id = item.UserID }, null) %> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.