加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 使用javascript的Mvc ActionLink

发布时间:2020-12-16 09:14:34 所属栏目:asp.Net 来源:网络整理
导读:我正在使用MVC,我有一个ActionLink调用我的控制器的Action的视图,我的问题是当我想在该操作链接的onClick()事件上调用 javascript函数时(因为该操作链接转换)执行时间的html标准标签).我该怎么办?有什么更好的方法? 这是我的ActionLink的代码: %=Html.Act
我正在使用MVC,我有一个ActionLink调用我的控制器的Action的视图,我的问题是当我想在该操作链接的onClick()事件上调用 javascript函数时(因为该操作链接转换)执行时间的html标准标签).我该怎么办?有什么更好的方法?
这是我的ActionLink的代码:

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

谢谢.

解决方法

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

<%=Html.ActionLink("View Report",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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读