【发布时间】:2021-12-23 17:34:33
【问题描述】:
我在选择每个类别时遇到问题,它无法显示每个类别的书籍。我的索引代码在这里
@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>
}
// 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();
}
调试的时候发现id分类、表单或者值是这样加载的 但是当我选择每个类别时,我会遇到这样的错误: 我认为我的 java 脚本有问题。但我无法弄清楚这一点。任何人都可以帮助我,非常感谢。
【问题讨论】:
-
问题解决了,我忘记传数据了。
标签: javascript c# asp.net .net