0

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?

Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
avi
  • 27
  • 2
  • 5
  • 2
    It's not valid by this way. Because `C#` code gets execute on server side, while `JavaScript` code execute on client inside browser. Use Html `` tag instate of `Html.ActionLink`. – Jalal Sep 26 '11 at 18:18

1 Answers1

0

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

Ivo
  • 8,172
  • 5
  • 27
  • 42