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

197
Views
No se puede cargar el seguimiento del libro por ID de categoría en la lista desplegable usando javascript

Tengo problemas para elegir cada categoría, no puedo mostrar el libro de cada categoría. Mi código de índice aquí

 @using (Html.BeginForm("Index", "BorrowBook", FormMethod.Post, new { name = "demoForm" })) { @Html.DropDownList("id_category", (IEnumerable<SelectListItem>)ViewBag.listTest, "-- Select Category --", new { onchange = "SelectedIndexChanged()" }) <div> Show list of book in the middle </div> }

Código en índice Y mi controlador así

 // GET: BorrowBook public ActionResult Index(string mess) { var query = context.categories.Select(c => new { c.id_category, c.name }); var userInfomatiom = (LibraryAsp.Models.User)Session["USER"]; if (userInfomatiom.Role.id_role == 1) { ViewBag.listP = publisherDao.getAll(); ViewBag.listC = categoryDao.getAll(); ViewBag.list = bookDao.getAll(); ViewBag.listTest = new SelectList(query.AsEnumerable(), "id_category", "name"); ViewBag.mes = mess; return View(); } else { return RedirectToAction("Error", "Home"); } } [HttpPost] public ActionResult Index (Category category) { ViewBag.listP = publisherDao.getAll(); ViewBag.listC = categoryDao.getAll(); ViewBag.list = context.books.Where(p => p.id_category == category.id_category).ToList(); return View(); }

Al depurar, encontré que la categoría, el formulario o el valor de identificación se cargan así Imagen en web Pero cuando elijo cada categoría, obtengo un error como ese: error en la web Creo que mi script Java está teniendo problemas. Pero no puedo entender esto. Alguien me puede ayudar, muchas gracias.

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

0

Resuelva el problema, es malo que me olvide de pasar los datos. debería ser así

 [HttpPost] public ActionResult Index (Category category) { var query = context.categories.Select(c => new { c.id_category, c.name }); ViewBag.listP = publisherDao.getAll(); ViewBag.listC = categoryDao.getAll(); ViewBag.list = context.books.Where(p => p.id_category == category.id_category).ToList(); ViewBag.listTest = new SelectList(query.AsEnumerable(), "id_category", "name"); return View(); }
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!