Call javascript from MVC controller action

后端 未结 9 1257
半阙折子戏
半阙折子戏 2021-02-01 07:04

Can I call javascript function from MVC controller action (not from view page) and get return value? How?


I need to make request to server

9条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 07:47

    Yes, it is definitely possible using Javascript Result:

    return JavaScript("Callback()");
    

    Javascript should be referenced by your view:

    function Callback(){
        // do something where you can call an action method in controller to pass some data via AJAX() request
    }
    

提交回复
热议问题