Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Can not load book follow by category id in dropdownlist using javascript

i'm having trouble while choose each category, it can't show book of each category. My index code here

@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>
}

Code in index And my controller like that

// 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();
        }

When debugging, i found that id category, form, or value is loaded like this Image in web But when i choose each category, i get bug like that: Bug in web I think my java script is having problem. But i can't figure out this. Any body can help me, many thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Problem solve, my bad to forget pass data. Should be like that

[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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda