Call javascript from asp.net mvc
How can i call a javascript function from a mvc controller similar to what you would do in webform开发者_StackOverflows with ICallbackHandler?
Is it possible? Thank you.
Controller actions cannot call javascript functions. They return action results. Javascript code should be contained on the client side. So if you want to call a javascript function that should execute under certain circumstances you could subscribe for the corresponding event and when this event is triggered call the function.
For example if you wanted to call a javascript function when a button is clicked using jQuery you could do the following:
$(function() {
// subscribe for the click event
$('#someId').click(function() {
// the button is clicked => execute some javascript function here
});
});
精彩评论