ASP.net mvc Call function on link click
I wa开发者_如何学Pythonnt to be able to call a method from a link click. The situation is I have a chat client within my website. When the user clicks on the Open Chat client link I want to fire off a method that updates all the contacts the user is allowed to talk to and than it fires off javascript to open the chat client.
Ive got the javascript to open the chat client firing but not the method before. All the method will do is update some database records that the chat client accesses (I only want to do this if they open the chat client otherwise it is overkill and an unneeded perf hit).
Thanks in advance
The easiest solution is to use jQuery (or any other js library) to make an ajax call to your action method. Depending on how your app works, you can make the call asyncrhonously, or wait for your method to respond before opening the chat window.
If using jQuery, the only line of js needed is:
$.get('/controller/method', function(response) { alert('db updated!') });
精彩评论