Data Haunting

Easy Solutions Destination

By

Asp.net MVC Image ActionLink

In Asp.net 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.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA
Change the CAPTCHA codeSpeak the CAPTCHA code
 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">