开发者

how to pass a parameter to actionlink from a script

开发者 https://www.devze.com 2023-04-08 18:20 出处:网络
I have a script: function FindSerial() { var textBoxValue = $(\"#clientSerial1\").val(); return textBoxValue;

I have a script:

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

    return textBoxValue;
};

My actionlink is :

@Html.ActionLink("talks", "ClientTalks", "Talk", 开发者_如何学编程new { id ="FindSerial()" }, null)

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


@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>

Something to consider:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号