Reputation: 211
I am using asp.net mvc 3. I have this code on my view.
<%
foreach(Team t in Model.AvailableTeams.AvailableTeams)
{ %>
<%= Ajax.ActionLink(t.Title
, "InviteTeamToChallenge"
, "Challenge"
, new{id = t.TeamId
, challengeId = Model.ChallengeId
, teamId = t.TeamId
, invitedByUserId = Model.userId}
, new AjaxOptions
{
OnSuccess = "hideLabel(teamId)"
} ) %>
<% } %>
i am trying to pass the teamId in anyway possible to a javascript function that can then hide the action link after it has been clicked. Right now, the javascript method is not getting called. here is my javascript:
function hideLabel(teamId) {
alert("in JS");
alert(teamId);
$('.teamId').hide();
}
I would also like to refresh a partial view on the page that lists teams that have been selected, but that is another problem to deal with after i get this piece.
Upvotes: 0
Views: 485
Reputation: 6000
Simply use
OnBegin="javascript:this.style.display='none'"
or
OnComplete="javascript:this.style.display='none'"
e.g.
@Ajax.ActionLink("Hide button before ajax", "myAction", new AjaxOptions { OnBegin="javascript:this.style.display='none'" })
or
@Ajax.ActionLink("Hide button after ajax", "myAction", new AjaxOptions { OnComplete="javascript:this.style.display='none'" })
Upvotes: 0
Reputation: 1210
You need to set unique id for each action link:
new AjaxOptions
{
OnSuccess = "hideLabel(" + t.TeamId + ")"
},
new { id="actionLink" + t.TeamId )
and than
function hideLabel(teamId) {
$('#actionLink' + teamId).hide();
}
Upvotes: 1