I am trying add image in @Html.ActionLink using ASP.Net MVC
MVC Code:
@Html.ActionLink(linkText: "Image Text", actionName: "Index", controllerName: "Home", routeValues: null, htmlAttributes: new { @class = "addimg" })
CSS:
.addimg {
background-image: url("/assets/images/img3.png");
background-repeat: no-repeat;
width: 348px;
height: 65px;
}
what mistake am doing in code? without linktext cant create a ActionLink
Please give suggestions...
Thanks

Ehsan SajjadRank #512 · 4.8K reputationPosted Jul 15, 2015, 1:21 AM EDT
public static class CustomHtmlHelepers { public static IHtmlString ImageActionLink(this HtmlHelper htmlHelper, string linkText, string action, string controller, object routeValues, object htmlAttributes,string imageSrc) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); var img = new TagBuilder("img"); img.Attributes.Add("src", VirtualPathUtility.ToAbsolute(imageSrc)); var anchor = new TagBuilder("a") { InnerHtml = img.ToString(TagRenderMode.SelfClosing) }; anchor.Attributes["href"] = urlHelper.Action(action, controller, routeValues); anchor.MergeAttributes(new RouteValueDictionary(htmlAttributes)); return MvcHtmlString.Create(anchor.ToString()); } } and in View you can use it this way: @Html.ImageActionLink("Link Display Text","Index","Home",null,null,"~/images/untitled.png")Vijay134 reputationPosted Jul 15, 2015, 1:29 AM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Jul 15, 2015, 1:51 AM EDT
Ehsan SajjadRank #512 · 4.8K reputationPosted Jul 15, 2015, 5:57 AM EDT
Ehsan SajjadRank #512 · 4.8K reputationPosted Jul 15, 2015, 5:59 AM EDT
http://developmentpassion.blogspot.com/2015/07/image-actionlink-html-helper-in-aspnet.html