Ante
Ante

Reputation: 8637

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"})%>

Upvotes: 3

Views: 309

Answers (1)

tvanfosson
tvanfosson

Reputation: 532595

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' } );
});

Upvotes: 10

Related Questions