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.

2

try removing the ; and adding : before-

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.