Search code examples
asp.netasp.net-mvchtml.actionlink

Image as link to action method


I have a question about using an image as link to a specific action in a controller.
I load my images from the database and show them in a view:

@foreach(var imgID in Model.DeliverablesIDsList)
{
    <div class='small-3 columns'>
        <img src="@Url.Action("ShowImage", "Deliverable", new { DeliverableID = imgID })" />
    </div>
}   
</div>

Now I would like to have a link around that image so that I can link to a view and send the linked DeliverableID with it.

How can I do this?


Solution

  • You should try this.

    @foreach(var imgID in Model.DeliverablesIDsList)
    {
        <div class='small-3 columns'>
            <a href="@Url.Action("ShowImage", "Deliverable", new { DeliverableID = imgID })">
               <img src="image-url" />
            </a>
        </div>
    }