Data Haunting

Easy Solutions Destination

By MVC Image ActionLink

In Mvc we usually use ActionLink like html.actionlink and ajax.actionlink . Now if you want to use Image in simple anchor tag it is quite easy but if you want to use image inside ActionLink it is some how tricky . In this post I will explain how to use Image inside Html.ActionLink and Ajax.ActionLink and some more guidance about how to use CSS inside ActionLink that is ActionLink with classes and style sheet .

  •  Use Image in simple Anchor tag without ActionLink

In MVC it is not necessary that every time we need to use Html.ActionLink for anchor tag instead for simplification we can use simple html anchor tag instead of Razor syntax . This one is specially helpful when you use it with Image . Below I have given example.

  • Image with Ajax.ActionLink

Now what if we have Ajax Request, In mvc if we really want to use MVC Ajax best practice we can do it differently . Below I have given Example

As I have described earlier that Ajax.ActionLink and Html.ActionLink take first argument as LInkText so here to do it we will use Replace function of C# and Html.Raw to return IHtmlString.

  • Image with Html.ActionLink

Html.ActionLink can do as following way but It is not necessary we can achieve same thing by using simple Html Anchor Tag as describe first.

  • ActionLink with css

Implementing above way  thing goes tricky when we want to use some more other property of Img classes or style property . We need to use “\” character as below.

ActionLink with Style sheet

ActionLink with Classes

What is your opinion ?

So this way you can use Html.ActionLink and Ajax.ActionLink with Image and also can apply css and style sheet .I hope this information will be useful to all of you. If you have any query you can comment below or you can mail me.


4 Responses to MVC Image ActionLink

  1. Absolutely brilliant – I looked everywhere for “image with @ActionLink, etc.” and found nothing until I found this gem! Thank you.

  2. Alina says:

    Thank you so much!! God bless you ! U really helped me!! ♥♥♥

Leave a Reply