我在侧边栏中有一个类别列表。@foreach (var item in Model) { <li><a href="~/Books/Category/@item.Title">@item.Title</a></li>}我想通过单击类别来显示该类别的产品。为此,我实现了方法 ViewCategory。public ActionResult ViewCategory(string name) { ... }但我不知道如何正确传递参数。我正在尝试写这样的东西,但我明白做错了什么......@Html.Action("ViewCategory", "Books", new {Title=item.Title})请帮帮我更新我有一个查看索引,以及一种显示我的产品列表的方法 public ActionResult Index() { HttpResponseMessage response = WebApiClient.GetAsync("Books").Result; var booksList = response.Content.ReadAsAsync<IEnumerable<BookDto>>().Result; return View(booksList); }选择类别时,我只需要显示属于该类别的产品。我用 PartialView 列出了类别<ul>@foreach (var item in Model) { @*<li><a href="~/Books/@item.Title"></a></li>*@ @Html.Action("ViewCategory", "Books", new { name = item.Title })}为此,我编写了一个我尝试使用的方法而不是 public ActionResult ViewCategory(string name) { HttpResponseMessage responseBooks = WebApiClient.GetAsync("Books").Result; List<BookDto> booksList = responseBooks.Content.ReadAsAsync<IEnumerable<BookDto>>().Result.ToList(); for (int i = 0; i < booksList.Count; i++) { if (booksList[i].CategoryName != name) { booksList.Remove(booksList[i]); } } return View("Category"); }但现在我有 NullReferenceException ......
- 3 回答
- 0 关注
- 322 浏览
添加回答
举报
0/150
提交
取消
