how to pass a parameter to actionlink from a script

旧城冷巷雨未停 提交于 2019-12-12 02:14:08

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/7559191/how-to-pass-a-parameter-to-actionlink-from-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!