Tell the guys how you can call the C # function from JavaScript, so that after execution you can get the result from the server into the code of the beehind. I used the UDP protocol to send information to the service and receive a response. Since the response is sent and received in the browser, you need to use JavaScript.

How to implement scripts and functions?

  • what from where should I call and where to show the result? - Grundy
  • Figures from the client strana are sent, for example, 2, on the service side, a file of some kind is scanned twice and then these scanned files must be sent to the client part - Vardan Vardanyan
  • Is the client a browser? - Grundy
  • yes it is a browser;) - Vardan Vardanyan
  • one
    And this is also a call to the c # function from the js code: window.location.href = "Home/Index"; . The browser creates a query, the Index method of the Home controller is executed on the server using standard routing and the result is returned. - Andrew B

1 answer 1

If I understand the question correctly, then AJAX will help you. Since there are no details, the answer will be generalized - tyts

example:

 $(document).ready(function () { $('#btnSendMessage').click(function (event) { event.stopPropagation(); var data = { 'message': $('#TextBoxSender').val(), } $.ajax({ url: 'MessageHandler', type: 'POST', data: JSON.stringify(data), cache: false, dataType: 'json', processData: false, contentType: "application/json; charset=utf-8", success: function (data) { if (data == true) { alert("Сообщение доставлено"); location.reload(); } else { alert("Внимание! Сообщение не доставлено!"); } }, error: function () { alert("Произошел сбой бла бла бла"); } }); }); 

})

Message handling method:

 [HttpPost] public JsonResult MeesageHandler(string data) { var result = "Сообщение " + data + "принято" return Json(result); } 
  • What details are needed? ; 0 - Vardan Vardanyan
  • Ideally, the description of the problem, you can even guess from the commentary. I understand you need to call the function c # method from the js script? This will help you ajax, for example. - Valery Gorbunov
  • Details added to the question text - Vardan Vardanyan
  • 1. To call a function from the browser, you can use the http post request. That is, using the standard "input" element and the submit attribute. The disadvantage of this method is that the server’s response will cause the page to reload. - Valery Gorbunov
  • 2. I usually use AJAX and jQuery. - Valery Gorbunov