Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
JS+ASP Net Core Obtener datos del controlador

surgió la pregunta: ¿Cómo obtener datos del controlador en asp net core usando js? Traté de enviar una solicitud de publicación de frente, pero me parece que hay una solución más elegante. Al mismo tiempo, necesito que esto suceda cuando cambie el html del elemento Seleccionar. Escribí un script que cambia el campo cuando el seleccionar cambios

 function Change_Aud() { var x = document.getElementById("Levelid").value; document.getElementById("Hardware_La").value = x ; }

Ejemplo de controlador

 public async Task<IActionResult> Get_Hardware_Unit(int id) { Level level = _context.Levels.Where(p => p.Number == id.ToString()).First(); return Content(level.Public_Hardware.ToString()); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Código de página de prueba en cshtml:

 @{ ViewData["Title"] = "Home Page"; int count = 5; } <script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script> <script> function myFunction(selectObject) { var value = selectObject.value; $("#selectnum").html(value); backendfunc(value); } function backendfunc(value) { $.ajax({ url: "/Test/Get_Hardware_Unit", type: "GET", data: { id: value }, success: function (res) { $("#convertnum").html(res); }, error: function (hata, ajaxoptions, throwerror) { $("#convertnum").html("convert failed"); } }); } </script> <div> <select name="num" id="num-select" onchange="myFunction(this)"> <option value="">--Please choose an option--</option> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> </div> <br /> <br /> <div> You select value is : <span id="selectnum"></span> </div> <br /> <br /> <div> After backend converted, here is : <span id="convertnum"></span> </div>

Mi función en el controlador:

 public async Task<IActionResult> Get_Hardware_Unit(int id) { string result = string.Empty; if (id == 1) { result = "①"; } if (id == 2) { result = "②"; } if (id == 3) { result = "③"; } return Content(result); }

Resultado de la prueba

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!