how to insert image in html action link? asp.net mvc
https://stackoverflow.com/questions/3627178
Full question
- c# - asp.net-mvc - actionlink |
- |
기타 팁
Html.ActionLink and Url.Action return the same URL. The difference is that the first creates an HTML element while the second returns just the URL to that action.
Another option is to use Url.RouteUrl or Html.RouteLink to create a link based off your route (to an action) instead of directly to an action.
One solution is to create an HtmlHelper extension method for creating an image-specific action link. A detailed tutorial can be found here.
If You are on MVC 3-4 with razor view engine then this may help you-
@Html.ActionLink("your link Name", "Action Method", "Controller",
new { style = "background-image:url('.././Images/imageyouwanttoshow.png')" },null)
Instead of using @Html.ActionLink("linkname","action","controller")
you can use following
<a href='@Url.Action("action", "controller")'>
<img src='@Url.Content("~/images/imageName.png")' />
"images" is my folder for storing the images.
@Url.Content()
is to know the path.
You can pass your action and the controller for that action to @Url.Action()
.
@Url.Action()
works similar to the @Html.ActionLink()
.
Now your link will get replaced by the image.