1

I have an anchor element with an image inside and I would like to use the @Html.ActionLink from ASP.Net MVC to create it:

<a class="element image-button image-left place-left" style="color: #3D1400">
   Some text here
   <img src="~/Content/Images/logo.png" />
</a>

Can anyone help me to do it? thanks

yosbel
  • 1,711
  • 4
  • 20
  • 32
  • So, there is not possible way to do it with Html.ActionLink, just with Action and putting the rest of the Html as usually? – yosbel Mar 10 '14 at 17:47
  • 1
    @yosoy In a project I worked on a while back we used a custom HtmlHelper named ImageActionLink for just this type of situation, so you could have a go at implementing such a thing. – Andreas Eriksson Mar 10 '14 at 17:51
  • Good idea, I'll try it too. For now I solved using the @Url.Action. Thanks a lot – yosbel Mar 10 '14 at 17:53

2 Answers2

4

Using ActionLink one can do the following in the view

@Html.ActionLink("View Details", "Detail", new { @class = "detailsIcon"})

and in your style sheet you can define something like

.detailsIcon
{
  background: url(AnImage.png);
}
TechnoBrat
  • 277
  • 1
  • 7
  • Yes, even Url.Action() as suggested by @Nathan is great. – TechnoBrat Mar 10 '14 at 17:57
  • Thanks, even when I solved with Url.Action, considering that the question was using Html.ActionLink I believe that your anwser is the most accurate. – yosbel Mar 10 '14 at 18:03
2

So I found a way of doing it with the @Url.Action method, instead of @Html.ActionLink

<a class="element image-button image-left place-left" style="color: #3D1400" href="@Url.Action("Index","Home")">
         Some text here
      <img src="~/Content/Images/logo.png" />
</a>

thanks @Nathan Koop for the link.

yosbel
  • 1,711
  • 4
  • 20
  • 32