How to start jquery when click actionlink

How to run jquery when clicking MVC ActionLink? I have an action that takes some time. I want to show the processing image until it returns. Is there a better way to do this?

+4
source share
3 answers

Give actionlink to the class:

@Html.ActionLink("","", new { @class:"delete" }) 

Then you can connect jQuery to the class name in the js file:

 $(document).ready(function() { $('.delete').click(function() { ///Code }); }); 

You can also work with id .

+4
source

You can also use @Ajax.ActionLink without the need for a jQuery script. For example, you can show the div when the page loads.

 <div> @Ajax.ActionLink("Link name", "Action", "Controller", new AjaxOptions { LoadingElementId = "loadingId", UpdateTargetId = "MyDataTable" }) </div> <div id="loadingId" style="display:none; color:Red; font-weight: bold"> <p>Please wait...</p> </div> <div id = "MyData" class="tablediv"> <table id = "MyDataTable" class="Grid"> <tbody id="chartdata"> </tbody> </table> </div> 
+3
source
 $('#element-id').live('click', function(e) { //do stuff here ... }); 

The trick is to give your action an id attribute id link so that you can use it as your element id:

 $('#html-attribute-id').live('click', function(e) { //do stuff here ... }); 
0
source

All Articles