MVC ActionLink的使用JavaScript [英] Mvc ActionLink with javascript

查看:97
本文介绍了MVC ActionLink的使用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与MVC的工作,我有一个调用我的控制器的作用的ActionLink的一个观点,我的问题是,当我想还呼吁采取行动链接的onclick()事件的JavaScript函数(作为操作链接转换为HTML的执行时间,非标准标签)。我应该怎么做呢?有什么更好的办法?
这里是我的ActionLink的code:

I'm working with MVC, I have a view with an ActionLink that calls an Action of my controller, my issue is when I want to call also a javascript function on the onClick() event of that action link (as that action link converts to html standart tag on execution time). How should i do this? what is the better way? Here is the code of my ActionLink:

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

感谢。

推荐答案

给的链接一个id(或类),并悄悄将处理程序使用JavaScript。使用jQuery例如:

Give the link an id (or class) and apply the handler unobtrusively using javascript. Example using 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>

这篇关于MVC ActionLink的使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆