简体   繁体   中英

How can I call Javascript function from Controller

I am making web/mvc project with Microsoft.AspnetCore.Mvc.Core version 5.0.0.0. When I send a request to the Controller with Postman, I want the javascript function to run without onclick.

In summary, I want to send request from postman to api controller and I want to be aware of view section. I tried with Viewbag in Home Controller but failed.

can i make it? Thanks in advance.

[ApiController]
    public  class DevicesController : ControllerBase
    {
        [HttpPost]
        [HttpPut]
        public IActionResult Focus(int id)
        {
      js function(LoadAndZoom) should work or call when this method works.  
        }

}

//js function 
this is the function i want it to work

function LoadAndZoom(id, tag, mapId, latitude, longitude) {

       
        };

postman url: https://localhost:11111/api/example/devices/focus?id=4

You can call a controller action from a JavaScript function but not the other way around. How would the server know which client to target? The server simply responds to requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM