【问题标题】:Pass the model value as parameter in html.actionlink Jquery method在 html.actionlink Jquery 方法中将模型值作为参数传递
【发布时间】:2012-10-29 10:05:48
【问题描述】:

我在 mvc razor 视图中使用以下代码生成动态链接。

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

我想将当前单击的模型(item.Name)的 id 或其他一些字段传递给 Jquery 方法的链接。

【问题讨论】:

    标签: jquery asp.net-mvc razor html.actionlink


    【解决方案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'));
       ...
    });
    

    【讨论】:

      【解决方案2】:

      将 ID 传递到您的 DeleteConfirm 方法中:

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

      【讨论】:

        猜你喜欢
        • 2020-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多