ActionLink with Image in ASP.NET MVC 2

As far as I know, this is one of the simplest ways to insert an ActionLink into your ASP.NET MVC 2 View with an image instead of text:

<a href="<%: Url.Action("Detail", new  { param1 = "blah" } )  %>">
  <img src="../../Content/images/magnifier.png" />
</a>

Any simpler solutions?

Advertisements

3 comments

  1. Here is my code for ActionLink in MVC 3 with Razor engine.

    @Html.ActionLink(" ", "Edit", new { id = item.Id },
    new { @class = "edit-item-link", @title = "Edit" })

    Link text is empty.

    And here is CSS class which adds image:

    .edit-item-link
    {
    display: block;
    width: 16px;
    height: 16px;
    background-image: url(images/edit.png);
    }

    Only if CSS is not enabled it will not work 😦

  2. Did it actually work for you ? For me it doesn’t, displays nothing unless I do put some string as first parameter. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s