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

206
Views
el método del controlador no devuelve ninguna respuesta después de una ejecución exitosa

Estoy publicando mis datos usando Ajax, los datos se publican con éxito en la base de datos. Pero no obtengo respuesta del método de Create . Me refiero a return RedirectToAction("Index"); la página no está redirigiendo a la página de índice.

 // POST: TestModels/Create [HttpPost] public ActionResult Create(TestModel testModel) { if (ModelState.IsValid) { db.TestModels.Add(testModel); db.SaveChanges(); return RedirectToAction("Index"); } return View(testModel); }

Además, probé:

 // POST: TestModels/Create [HttpPost] public JsonResult Create(TestModel testModel) { if (ModelState.IsValid) { db.TestModels.Add(testModel); db.SaveChanges(); return Json(new { success = true, responseText = "Your message successfuly sent!" }, JsonRequestBehavior.AllowGet); } return Json(new { success = false, responseText = "Error." }, JsonRequestBehavior.AllowGet); }

Todavía no recibo ninguna respuesta de Json .

Mi función javascript::

 <script> $(document).ready(function () { $('#btn_submit').click(function () { var testModel = { FirstName: $('#FirstName').val(), LastName: $('#LastName').val(), Gender: $("input[name='Gender']:checked").val(), Contact: $('#Contact').val(), Faculty: $('#Faculty').val(), RegNepaliDate: $('#RegNepaliDate').val() }; alert(JSON.stringify(testModel)); $.ajax({ type: "POST", url: "/TestModels/Create", data: JSON.stringify(testModel), contentType: "application/json;charset=utf-8", dataType: 'json', success: function (response) { console.log(response); if (response.success) { console.log(response.responseText); console.log(data); } }, error: function (response) { alert("failed..."); } }) }) }) </script>

Los datos se publican en el servidor y, cuando navego por la página Index , también se muestran los datos recién insertados. Además, cuando hago clic en el botón Enviar de la página Create , los datos del formulario se aclaran, pero todos los datos se muestran en la barra de direcciones URL.

https://localhost:44399/TestModels/Create?FirstName=machhi&LastName=go&Gender=male&Contact=5589512369&Faculty=science&RegNepaliDate=2021-05-01

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

0

¿Podría agregar el archivo de biblioteca jQuery faltante como "

 <script src="~/Scripts/jquery-3.4.1.min.js"></script> <script src="~/Scripts/jquery-3.4.1.slim.min.js"></script>

" para obtener la respuesta del controlador.

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!