0

I have my View page where i have this code:

<%: Html.ActionLink("Edit", "Edit", "Admin", new { id = item.Username })%>

And here is my controller

public ActionResult Edit(String id)
    {
        String x = id;
    }

But String x have value "null".Action Result is in Controller Admin so that is not mistake.Also I use item.Username to show results in table and it works fine.

If I try with this in View

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

I get error 404.

Does anybody know where is my mistake?

David Pilkington
  • 13,528
  • 3
  • 41
  • 73
daidai
  • 531
  • 5
  • 10
  • 22

3 Answers3

0

You can use the following overload of ActionLink Helper:

<%: Html.ActionLink("Edit", "Edit", new { Controller = "Admin", Action = "Edit", id = item.Username  } )%>

That should do the job.

Vishal Sharma
  • 2,773
  • 2
  • 24
  • 36
Gerard
  • 2,649
  • 1
  • 28
  • 46
  • This code sends me to page ../Admin/Edit/item.Username. Can you tell me how to create code view for this? – daidai Nov 14 '13 at 10:52
0

Tried Url.Action

<a href="@(Url.Action("Edit", "Action", new { id = item.Username }))"></a>
Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79
0

Try the another overload:

<%: Html.ActionLink("Edit", "Edit", new RouteValueDictionary() {{"id",item.Username}}) %>

Click here for more information