Home > Net >  How can I call Javascript function from Controller
How can I call Javascript function from Controller

Time:09-11

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

CodePudding user response:

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.

  • Related