3

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"?

3 Answers 3

5

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" 
    }
)
Sign up to request clarification or add additional context in comments.

Comments

0

You could used Url.Action instead?

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

1 Comment

Why using something like this when there's already an ActionLink overload which allows to achieve that?
0
@Html.ActionLink("EditLink","Edit", "EditProg", new { id = item.EmpID })

2 Comments

Hi @vaibhav-parab, welcome to the community. I'm reviewing your answer and I noticed some potential improvements. 1) Please use the correct markdown for the code segments (see stackoverflow.com/editing-help#syntax-highlighting) and 2) provide some additional commentary on what exactly your answer does/change in relation to question. Thanks!
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.