使用javascript的Mvc ActionLink

lid*_*min 3 asp.net-mvc

我正在使用MVC,我有一个ActionLink调用我的控制器的Action的视图,我的问题是当我想在该操作链接的onClick()事件上调用javascript函数时(因为该操作链接转换)执行时间的html标准标签).我该怎么办?有什么更好的方法?这是我的ActionLink的代码:

<%=Html.ActionLink("View Report", "GeneratePdf", new { strProductId = myObject.productId})%>
Run Code Online (Sandbox Code Playgroud)

谢谢.

tva*_*son 12

给链接一个id(或类)并使用javascript不引人注意地应用处理程序.使用jQuery的示例:

<%=Html.ActionLink("View Report", "GeneratePdf",
     new { strProductId = myObject.productId},
     new { id = "reportLink" } )%>


<script type="text/javascript">
    $(function() {
        $('#reportLink').click( function() {
             ... do what you need to do...
             // return false; // to cancel the default action of the link
        });
    });
</script>
Run Code Online (Sandbox Code Playgroud)