Iterating through a viewbag of selectlist items

Jan 24 2019 6:32 AM
Hi folks
 
I have the following line in a controller:
 
ViewBag.Assignments = new SelectList(db.class_table_Assignment, "ID", "Title");
 
In the view (Razor) file I'm looking to iterate through the ViewBag and pull out entries were the ID = "isok"; then populate a DropDownList.
 
The following line : add_Li_Node(tmp_entry); is where I'm looking to extract the values in the ViewBag.  I assumed the for loop would assign the contents of one row of the ViewBag to the variable tmp_entry during each iteration.  The actual output I'm getting in the DropDown is "undefined".  The for-loop is iterating correctly for the number of rows in the ViewBag.
 
So basically, I'm asking if anyone can help me iterate through the contents of a ViewBag of SelectList items and view each entry before deciding to keep it. 
 
Thanks in advance. 
 

Answers (6)