I need to filter products by categories and provide link to each category.
This is the method from StoreController:\[code\]public ViewResult Content(string category = null, int page = 1) { var model = new StoreContentViewModel { Items = _itemsRepository.GetItems() .Where(i => i.Product.Category == category || i.Product.Category == null) .OrderBy(i => i.ItemId) .Skip((page-1)*PageSize) .Take(PageSize), PageInfo = new PageInfo { TotalItems = category == null ? _itemsRepository.GetItems().Count() : _itemsRepository.GetItems().Where(i => i.Product.Category == category).Count(), CurrentPage = page, ItemsPerPage = PageSize }, CurrentCategory = category }; return View(model); }\[/code\]And here is the method from NavigationController: \[code\] public PartialViewResult Menu(string category) { ViewBag.SelectedCategory = category; IEnumerable<string> result = _itemsRepository.GetItems() .Select(i => i.Product.Category) .Distinct() .OrderBy(i => i); return PartialView(result); }\[/code\]Partial View for this Menu method: \[code\]@model IEnumerable<string>@Html.ActionLink("All products", "Content", "Store")@foreach (var link in Model){@Html.RouteLink(link, new { controller = "Navigation", action = "Menu", category = link, page = 1 }, new { @class = link == ViewBag.SelectedCatgory ? "selectedLink" : null } )}\[/code\]In my model 1 item contains 1 product (ProductId is the foreign key in Items table). When I run the app I get an error: "The value cannot be equal to null or empty. Parameter name: controllerName". Unit test for this action method also fails.
Without adding categry filtering everything works. I think the problem is in lines where I get "Category" property from the _itemsRepository, (cause "filter" unit test also fails): \[code\]_itemsRepository.Product.Category \[/code\]Is it right? If it is I want to know is there any other way to access "Category" property??
Thanks in advance.
This is the method from StoreController:\[code\]public ViewResult Content(string category = null, int page = 1) { var model = new StoreContentViewModel { Items = _itemsRepository.GetItems() .Where(i => i.Product.Category == category || i.Product.Category == null) .OrderBy(i => i.ItemId) .Skip((page-1)*PageSize) .Take(PageSize), PageInfo = new PageInfo { TotalItems = category == null ? _itemsRepository.GetItems().Count() : _itemsRepository.GetItems().Where(i => i.Product.Category == category).Count(), CurrentPage = page, ItemsPerPage = PageSize }, CurrentCategory = category }; return View(model); }\[/code\]And here is the method from NavigationController: \[code\] public PartialViewResult Menu(string category) { ViewBag.SelectedCategory = category; IEnumerable<string> result = _itemsRepository.GetItems() .Select(i => i.Product.Category) .Distinct() .OrderBy(i => i); return PartialView(result); }\[/code\]Partial View for this Menu method: \[code\]@model IEnumerable<string>@Html.ActionLink("All products", "Content", "Store")@foreach (var link in Model){@Html.RouteLink(link, new { controller = "Navigation", action = "Menu", category = link, page = 1 }, new { @class = link == ViewBag.SelectedCatgory ? "selectedLink" : null } )}\[/code\]In my model 1 item contains 1 product (ProductId is the foreign key in Items table). When I run the app I get an error: "The value cannot be equal to null or empty. Parameter name: controllerName". Unit test for this action method also fails.
Without adding categry filtering everything works. I think the problem is in lines where I get "Category" property from the _itemsRepository, (cause "filter" unit test also fails): \[code\]_itemsRepository.Product.Category \[/code\]Is it right? If it is I want to know is there any other way to access "Category" property??
Thanks in advance.