How to embed image in html action link? asp.net mvc

I have navigation and many links to my web project from html actions links. They are ugly with underlining. I would like to insert some image with a name or play with action link styles. Is it possible? How to do it?

Thanks and take care, Ragims

+7
c # asp.net-mvc actionlink
source share
5 answers

You can use css to remove underscores or put a background image, otherwise you could just create a link like this:

<a href="<%: Url.Action("Action", "Controller")%>"><img src="yourimg.jpg" /></a> 
+17
source share

Html.ActionLink and Url.Action return the same URL. The difference is that the first creates an HTML element, and the second only returns the URL of this action.

Another option is to use Url.RouteUrl or Html.RouteLink to create a link based on your route (to the action), and not directly to the action.

+2
source share

One solution is to create an HtmlHelper extension method to create a link to a specific image. A detailed guide can be found here .

0
source share

If you're on MVC 3-4 with a razor view engine, this might help you -

 @Html.ActionLink("your link Name", "Action Method", "Controller", new { style = "background-image:url('.././Images/imageyouwanttoshow.png')" },null) 
0
source share

Instead of using @Html.ActionLink("linkname","action","controller") you can use the following

 <a href='@Url.Action("action", "controller")'> <img src='@Url.Content("~/images/imageName.png")' /> 

"images" is my folder for storing images. @Url.Content() - know the path. You can pass your action and controller for this action to @Url.Action() . @Url.Action() works similarly to @Html.ActionLink() . Your link will now be replaced by an image.

0
source share

All Articles