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

179
Views
Redirigir a una página en C# Aspnet MVC después de una solicitud exitosa de Ajax Post

Estoy tratando de hacer una redirección a la URL después de hacer una solicitud de Ajax Post pero mi código no está redirigiendo

Aquí está mi código de muestra.

ventana.onload = función () { let base_url = ventana.ubicación.protocolo + "//" + ventana.ubicación.nombre de host + ":" + ventana.ubicación.puerto + "/"; // creando una url base let URL = base_url+"api/Teacherdata/AddTeacher"; //creando una ruta let form = document.forms.new_teacher;

 form.onsubmit = processForm; function processForm() { let fname = form.teacherfname; let lname = form.teacherlname; let salary = form.salary; let hiredate = form.hiredate; let employeenumber = form.employeenumber; var xhttp = new XMLHttpRequest(); xhttp.open("POST", URL, true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send("teacherfname=" + fname.value + "&teacherlname=" + lname.value + "&teacheremployeenumber=" + employeenumber.value + "&teachersalary=" + salary.value + "&teacherhiredate=" + hiredate.value); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { window.location.href = base_url + "teacher/list"; } }; }

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

para redirigir al método de acción mvc que puede usar

 window.location.href = "/{controller}/{action}/{params}";

alternativamente, si está escribiendo su script en cshtml, también puede usar

 window.location.href = '@Url.Content("~/{controller}/{action}/{params}")';
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!