如何在OnBegin函数上获取发件人标记?

时间:2013-08-17 10:08:09

标签: c# asp.net-mvc jquery razor actionlink

我有一个列表,每行都有一个由Ajax.ActionLink创建的链接。我想访问点击OnBegin函数的标签并将其转换为jQuery对象。

谢谢:)

更新

这是我创建链接的操作代码:

@Ajax.ActionLink("linkText", "action", new AjaxOptions()
{
    OnBegin = "myfunction",
})

这是javascript函数:

<script type="text/javascript">
   function myfunction() {
     //I need refer to link that clicked
   }
</script>

1 个答案:

答案 0 :(得分:1)

我建议您将此功能用于ajax.actionlink

public static MvcHtmlString ActionLink(
    this AjaxHelper ajaxHelper,
    string linkText,
    string actionName,
    Object routeValues,
    AjaxOptions ajaxOptions,
    Object htmlAttributes
)

在htmlAttributes中,您可以提供new {class='lnk'}

使用jQuery查找使用$(this)单击的链接。您还可以获取父级,下一个html元素。

例如(jQuery):

$('.agree').live("click", function(){
        var currentId2 = $(this).parents(".user").attr('id');
        alert (currentId2);
        call the function() you are supposed to call in ActionBegin

});

示例演示,我有很多div,每个都有一个链接。我需要找到点击的链接(所有链接都有名为agree的类。

另一篇参考资料

How to use $(this) inside MVC3 Ajax.ActionLink OnBegin,OnComplete Events

相关问题