如何传递参数从脚本到ActionLink的 [英] how to pass a parameter to actionlink from a script

查看:356
本文介绍了如何传递参数从脚本到ActionLink的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本:

function FindSerial() {
   var textBoxValue = $("#clientSerial1").val();

    return textBoxValue;
};

我的ActionLink的是:

My actionlink is :

@Html.ActionLink("talks", "ClientTalks", "Talk", new { id ="FindSerial()" }, null)

我想使用的功能,以获取ID;怎样才能做到呢?

I want to use the function in order to get id ; how can it be done?

推荐答案

@Jalai阿米尼是正确的。你需要使用jQuery来处理它。事情是这样的:

@Jalai Amini is right. You will need to handle it with jquery. Something like this:

@Html.ActionLink("talks", "ClientTalks", "Talk", new { id="talklink"})

<script>
  $(function () { 
    $('#talklink').click(function () {
        document.location.href = $(this).attr("href") + "?id=" + FindSerial();
    }
});

</script>

要考虑的事情:

在这种方式要创建在客户端的URL,所以它不能使用MVC路线。在我的例子,它将把ID作为查询参数,但它可能是另一回事。

In this way you are creating the url in the client side, so it can't use the mvc routes. In my example, it will be putting the id as a querystring parameter, but it could be another thing.

这篇关于如何传递参数从脚本到ActionLink的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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