2012-10-29 141 views
0

我正在使用mvc剃刀视图中的以下代码生成动态链接。在html.actionlink中传递模型值作为参数Jquery方法

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

我想通过id或模型(item.Name)的其他字段当前点击链接到jquery方法。

回答

0

传递ID到您的DeleteConfirm方法:

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

,我可以从代码中看到,您使用jquery,这样你就可以创建任何attributes,然后绑定事件,还记得定制约data属性。

$('.emp_delete').click(function(e) 
{ 
    e.preventDefault(); 
    var $this = $(this); 
    alert($this.attr('title')); 
    ... 
});