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

前端 未结 6 1564
-上瘾入骨i
-上瘾入骨i 2020-12-05 04:24

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

i wan to call one method which is in java script but how to call it within html.actionlink in same

6条回答
  •  一生所求
    2020-12-05 05:20

    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 */ });
    

提交回复
热议问题