6

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

Chandu
  • 74,913
  • 16
  • 123
  • 127
SirRoland
  • 157
  • 2
  • 2
  • 10

2 Answers2

8

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

Jamie Dixon
  • 49,653
  • 18
  • 119
  • 157
  • 2
    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" }` – phloopy May 08 '12 at 16:18
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"})
TAIT
  • 61
  • 3
  • 8