7

How I can add a class for Ajax.ActionLink?

@Ajax.ActionLink("Remove this photo","RemovePhoto","Admin",new{Id=Model.filename, @class="ActionClass"},new AjaxOptions{OnSuccess = "RemoveSuccess"})

but this method don't create css class for this ActionLink. My class is added to the url: AdminTools/RemovePhoto/ffff.JPG?class=RemovePhoto

1
  • Hi SirRoland. Did my answer help to solve your problem. If so, please can you mark it as accepted. Cheers. Commented Mar 20, 2012 at 8:18

2 Answers 2

9

You can use the (AjaxHelper, String, String, Object, AjaxOptions, Object) method signature for this.

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

As you can see, the final parameter is a collection of HTML attributes.

Source: http://msdn.microsoft.com/en-us/library/dd470546.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Since class is a reserved keyword you'll need to use @class as the key. So your last parameter might look something like this: new { @class = "magic" }
5

Should be use like this:

@Ajax.ActionLink("Remove this photo","RemovePhoto","Admin",new{Id=Model.filename          },new AjaxOptions{OnSuccess = "RemoveSuccess"} , new {@class="Action Class"})

Comments

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.