In ASP.NET 4.0 MVC 3, How to make html.actionlink without text but with image inside. We do not want to create a helper class

Posted on 2011-04-21
Last Modified: 2012-08-13
Let me explain the scenario. We have a index page where we are displaying 4 products, and one of the sample product is attached as an image (product image). Along the product there is Details and Order now image button.
Click on Details image button will open a model popup containing details about the product, this also attached as product detail popup image

We are using ASP.NET 4.0 MVC 3 Razor View, The problem we are facing is we are not able to use HTML.Actionlink with image, were as with Text we are able to call model popup please have a look at my third attached product with text link image

We have googled for some solution, but every were they are mentioning to use helper class. We want to avoid it, if there are any other straight forward solution available.

Sincere appreciation for any help

Question by:swsbuyer
    LVL 4

    Accepted Solution

    <a href="<%= Url.Action("ActionName", "ControllerName") %>">
        <img src="<%= Url.Content("~/Content/img/imgname.jpg") %>" /></a>

    Open in new window

    Best regards,
    LVL 4

    Assisted Solution

    Or you can try to do something like this
    @Html.ActionLink(" ", "Edit", new { id = item.Id },
    new { @class = "edit-item-link", @title = "Edit" })

    Open in new window

    Link text is empty.

    And here is CSS class which adds image:

    display: block;
    width: 200px;
    height: 60px;
    background-image: url(images/edit.png);

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now