aakash jalodkar
aakash jalodkar

Reputation: 53

ActionLink does not show id parameter

My code is very simple and listed below:

I just want to pass id to the controller when I click on actionlink.

        foreach (var item in Model)
        {
            <tr>

                <td>@item.Name</td>

                <td>@item.Cause</td>

                <td>@Html.ActionLink("Edit","EditA","N",null,new {id=item.ActId})</td>
            </tr>
        }

With the above code currently the URL is generated like "N/EditA".

But I want the URL in this format "N/EditA/id". Any suggestions?

Upvotes: 0

Views: 443

Answers (2)

Spider man
Spider man

Reputation: 3330

You can try the following

@Html.ActionLink("Edit","EditA","N",new {id=item.ActId})

Upvotes: 0

user3559349
user3559349

Reputation:

You using the overload incorrectly and adding the id as a html attribute, not as a route value. It needs to be

@Html.ActionLink("Edit", "EditA", "N", new { id = item.ActId }, null)

Refer documentation

Upvotes: 1

Related Questions