0

I am generating dynamic links using below code in mvc razor views.

@foreach (App.Models.Users item in Model )
{
@Html.ActionLink("Delete", "DeleteEmp", new { id = item.Id }, new { onclick = "DeleteConfirm()" })
}

i want to pass the id or some other filed of model(item.Name) currently clicked link to Jquery method.

User_MVC
  • 251
  • 2
  • 7
  • 21

2 Answers2

1
@Html.ActionLink("Delete", "DeleteEmp", new { id = item.Id }, new { @class="emp_delete", title=item.Name })

As I can see from tags, you using jquery, so you can create any attributes and then bind events, also remember about data for custom attributes.

$('.emp_delete').click(function(e)
{
   e.preventDefault();
   var $this = $(this);
   alert($this.attr('title'));
   ...
});
webdeveloper
  • 17,174
  • 3
  • 48
  • 47
0

Pass the ID into your DeleteConfirm method:

@Html.ActionLink("Delete", "DeleteEmp", new { id = item.Id }, new { onclick = "DeleteConfirm(" + item.Id ")" });
James
  • 80,725
  • 18
  • 167
  • 237