John Vicencio

John Vicencio

  • NA
  • 73
  • 1.2k

Adding Search Filter and View of Enum

Aug 20 2017 1:41 PM
I'm trying to follow this tutorial https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/adding-search
 
My model has an enum of category of items. What I'm trying to do is:
 
1. Assuming there's a "model" class with properties (id, name, category in Enum)
2. Create a LINQ query of List collection and assign to ViewBag
3. So that this list is shown on DropDownList (in view) @Html.DropDownList("Category", "All)
4. If you select, "All", all items should be shown as you first load the page
5. If not, then show all the items under that category
6. Making sure that the drop down shown "distinct" (as per the link above)
 
Problem:
 
1. Everything works but on first load of the page when you compile, the drop down on the view shows "All" as the first option. It should have shown all items with their category
2. However the items show up upon selecting the actual categories
 
Advise. 

Answers (2)