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

188
Views
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 answers
Answer question

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 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!