Search code examples
sqllistasp.net-coreviewbag

How to add a string value to the front of viewbag SQL query list


How do I get my "ALL" at the top of the list?

When I use .Insert(0, "ALL") it doesn't work either.

CODE:

// Category
var CategoryFilter = (from r in _context.INT_CertificationCategories select r.Category).Distinct().ToList();
CategoryFilter.Add("ALL");
ViewBag.CategoryList = CategoryFilter;

Solution

  • Use the following code:

    CategoryFilter.Insert(0,"ALL")