1

I am working on ASP.NET MVC3 application. In my razor view I use @HTML.ActionLink to implement delete functionality for my custom image gallery. However when I show enlarged image I want to hide this link, and when the user clicks it back to thumb size I want to show the link again.

Here is my razor code:

<span class="document-image-frame">
        @if (image != null)
        { 
            <img src="file:\\105.3.2.7\upload\@image.Name" alt="docImg" style="cursor: pointer;" />
            @Html.ActionLink("Изтрий", "DeletePicture", new { documentImageID = image.Id }, new { @class = "delete" })
        }
        </span>

Then my jQuery script:

$('.document-image-frame img').click(function () {
    $(this).parent().toggleClass("document-image-frame");
    //$(this).parent().child('a').hide();
})  

This part - $(this).parent().toggleClass("document-image-frame"); is working fine but I don't know how to access the actionlink in order to show-hide it.

palaѕн
  • 72,112
  • 17
  • 116
  • 136
Leron
  • 9,546
  • 35
  • 156
  • 257

1 Answers1

2

You can find the link like this:

$(this).parent().find("a.delete").show(); // or .hide()

I like to also use the class to specify the link to delete, in case you may want to add other links in the future and you want them to behave differently...

Tallmaris
  • 7,605
  • 3
  • 28
  • 58
  • Thanks, this is what I need. Could you tell me how I can check if the link is show/hidden in order to know what to do when the user clicks an image or is there some toggle trick that I can use to play with the `a.delete` visibility? – Leron Jun 10 '13 at 11:09
  • 1
    `a.delete:visible` checks for visibility and `a.delete:hidden` checks if elem is hidden. – Jai Jun 10 '13 at 11:22
  • Also, the `toggle()` method toggles between hide and show. Or you can use the `toggle()` binder if you are in jQuery < 1.8, since it has been deprecated after that. You can refer to this SO answer to rewrite your own: http://stackoverflow.com/questions/14382857/what-to-use-instead-of-toggle-in-jquery-1-8 – Tallmaris Jun 10 '13 at 12:26