开发者

ASP.NET MVC - Using HtmlHelpers to create hyperlink image

开发者 https://www.devze.com 2023-01-09 06:21 出处:网络
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

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>


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>.

0

精彩评论

暂无评论...
验证码 换一张
取 消