How to create image link in ASP.NET MVC?

Well, how to create a link to a picture, for example, up or down in the votes (left) from the link below? (link activated by ajax)

<%= Ajax.ActionLink("Vote!",
                    "AddPictureVote",
                    "Vote",
                    new {id = Model.PictureId},
                    new AjaxOptions{UpdateTargetId = "addvote"})%>
+3
source share
1 answer

I think this is the main idea. You can fill in the details / adapt as necessary to your markup and model / actions.

$('.upvote').click( function() {
    $(this).addClass('highlight');
    $(this).nextAll('.downvote:first').removeClass('highlight');
    $.post( '<%= Url.Action( "vote", new { id = Model.ID } %>', { vote: 'up' } );
});

$('.downvote').click( function() {
   $(this).addClass('highlight');
   $(this).prevAll('.upvote:first').removeClass('highlight');
   $.post( '<%= Url.Action( "vote", new { id = Model.ID } %>', { vote: 'down' } );
});
+10
source

Source: https://habr.com/ru/post/1711823/


All Articles