'MVC @Html.ActionLink with Name

I have the following

@Html.ActionLink("Edit", "EditProg", new { id = item.ID }) 

I like to know how to also supply the above with a name as I need trap this name before it is submitted. Is there something like name = "EditLink"?



Solution 1:[1]

You mean like adding a name attribute to the anchor (even if this attribute is not valid on an anchor)?

@Html.ActionLink(
    "Edit",                        // linkText
    "EditProg",                    // actionName
    new { id = item.ID },          // routeValues
    new { name = "EditLink" }      // htmlAttributes
)

or sending it to the controller as query string parameter?

@Html.ActionLink(
    "Edit",                 // linkName
    "EditProg",             // actionName
    new {                   // routeValues
        id = item.ID, 
        name = "some name" 
    }
)

Solution 2:[2]

You could used Url.Action instead?

<a href="@Url.Action("EditProg")" id="@item.ID" name="editlink" >

Solution 3:[3]

@Html.ActionLink("EditLink","Edit", "EditProg", new { id = item.EmpID })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Darin Dimitrov
Solution 2 Doug Chamberlain
Solution 3 Dharman