Skip to content
Advertisement

how to call javascript function in html.actionlink in asp.net mvc?

How can one call a javascript function in html.actionlink in asp.net mvc?

I want to call one method, which is in JavaScript, but how I call it within html.actionlink in the same page?

Advertisement

Answer

you need to use the htmlAttributes anonymous object, like this:

<%= Html.ActionLink("linky", "action", "controller", new { onclick = "someFunction();"}) %>

you could also give it an id an attach to it with jquery/whatever, like this:

<%= Html.ActionLink("linky", "action", "controller", new { id = "myLink" }) %>


$('#myLink').click(function() { /* bla */ });
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement