0

What's the best practice method for creating images that are hyperlinks in ASP.NET MVC with the html helpers (because I want to supply the controller/action parameters and let Routing create the full URL for me)?

This is what I've ended up with but I feel it's a bit rubbish and is the result of ages staring at it not being able to see the wood for the trees:

<a href="<%= ResolveUrl("~/") %>"><img src="<%= ResolveUrl("~/Content/LogoCaption48.png") %>" /></a>

1 Answer 1

1

I don't know if it is best practice, but typically when I need an image to be a link in MVC, I do the following:

<%= Html.ActionLink("[replacethis]", myRouteStuff).Replace("[replacethis]", "<img src=""/images/myImage.jpg""/>" %>

I guess I have been too lazy to write a proper HTML Helper, but it works rather well and still maintains a rather clean look </subjective>.

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

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.