Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create picture link in ASP.NET MVC?

Well, how to create picture link like this up or down votes (on the left) from link below? (ajax enabled link)

<%= Ajax.ActionLink("Vote!",
                    "AddPictureVote",
                    "Vote",
                    new {id = Model.PictureId},
                    new AjaxOptions{UpdateTargetId = "addvote"})%>
like image 671
Ante Avatar asked Nov 21 '25 09:11

Ante


1 Answers

I think this is the basic idea. You can fill in the details/adapt as needed 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' } );
});
like image 138
tvanfosson Avatar answered Nov 23 '25 22:11

tvanfosson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!