开发者

Call javascript from asp.net mvc

开发者 https://www.devze.com 2023-02-16 11:54 出处:网络
How can i call a javascript function from a mvc controller similar to what you would do in webform开发者_StackOverflows with ICallbackHandler?

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
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消