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:
JavaScript
x
2
1
<%= Html.ActionLink("linky", "action", "controller", new { onclick = "someFunction();"}) %>
2
you could also give it an id an attach to it with jquery/whatever, like this:
JavaScript
1
5
1
<%= Html.ActionLink("linky", "action", "controller", new { id = "myLink" }) %>
2
3
4
$('#myLink').click(function() { /* bla */ });
5