开发者

how to pass a parameter to actionlink from a script

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜