Reputation: 4791
I was wondering is there some way to hide one row if action link is clicked in MVC, but pass via action link anyway. I'm just trying to hide it on clients page.
Like here for example. When user click on Add Friend action link whole row will be hidden. Should I do this with JavaScript for example?
This is my current view:
@model IEnumerable<DesignedAppNew.Models.UserProfile>
@{
ViewBag.Title = "ListAllFriends";
}
<script src="~/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
$("ID").click(function () {
$(this).closest("tr").hide();
});
});
</script>
<h2>Add some new friends:</h2>
<table>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.UserId)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.ActionLink("Add Friend", "AddNewFriend", new { id = "ID" })
</td>
</tr>
}
</table>
Upvotes: 0
Views: 1118
Reputation: 18883
You can use jquery for this as :-
$(document).ready(function(){
$(".friend").click(function(){
$(this).closest("tr").hide();
});
});
In your update all actionlinks will have same id this is wrong do it as :
@Html.ActionLink("Add Friend", "AddNewFriend", null, new { @class="friend" })
Upvotes: 1
Reputation: 3228
You cannot repeat ID in your HTML, Try this;
@Html.ActionLink("Add Friend", "AddNewFriend", null, new { @class = "addfriend" })
$(document).ready(function () {
$(".addfriend").click(function (event) {
event.preventDefault();
$(this).closest("tr").hide();
});
});
Upvotes: 1