views:

275

answers:

5

Hi everyone,

I'm using the Ajax.Actionlink from the MVC framework and everything works fine with my targets and partial views. However I've seen that the html output doesn't add the "id" attribute to the resulting tag.

Is there any way how I can add it?

Thanks in advance

A: 

You need to use new { id = "myId" } in the object htmlAttributes parameter, available in several of its constructors. Or you can fill it using the IDictionary<string, string> htmlAttributes also available in several of its constructors.

Yuriy Faktorovich
He needs the routeValues parameter. HtmlAttributes would set the id attribute of the anchor tag itself.
jcm
My understanding of his question was that he wanted <a id="myId">a</a>
Yuriy Faktorovich
I think that's what's being asked for - "add the "id" attribute to the resulting tag"? This answer sounds correct.
cxfx
A: 

Use the signature that includes the route values:

<%= Ajax.ActionLink( "Link",
                     "Action",
                     new { id = Model.ID },
                     new { ...here there be AjaxOptions...} ) %>
tvanfosson
A: 

I believe you're looking for the routeValues parameter.

<%= Ajax.ActionLink("SomeAction", "SomeController", new { id = ID_HERE }, null) %>
jcm
A: 

Try one of the overloads, like this one:

public static string ActionLink(
    this AjaxHelper ajaxHelper,
    string linkText,
    string actionName,
    Object routeValues,
    AjaxOptions ajaxOptions,
    Object htmlAttributes
)

Then you can specify the id in the htmlAttributes parameter, e.g.

new { id = "myIdValue" }
cxfx
A: 

Thank you everybody! it worked with the parameter htmlAttributes. You're the best!

cer
This should at best be a comment. Please choose a correct answer.
Yuriy Faktorovich