In combination with a ViewModel (for my business logic) I am using the ViewData[""] object to pass lists to my view with data from the database.
I am using 3 lists and I link them to my Model
Only one of these lists has items fetched from the database like so:
ViewData["Materials"] = StockRepository.GetMaterialTypes();
However... the other 2 lists should be empty by default and will get filled using jQuery when the user selects an item from the first list.
Right now, I have to fake 2 empty lists by returning an empty search from the database.
ViewData["Brands"] = StockRepository.GetBrands();
ViewData["ModelTypes"] = StockRepository.GetModelTypes();
The GetBrands and GetModelTypes methods actually return nothing. They do something like this to make sure nothing is returned!
public static IEnumerable<SelectListItem> GetBrands()
StockManagementDataContext db = new StockManagementDataContext();
var brands = from m in db.Material
[b]where m.Description == "ABC"[/b]
select new SelectListItem
Text = m.Description,
Value = m.MaterialId.ToString(),
: is it possible to initialize ViewData["Brands"] with an empty list or is there another more efficient way to link the model to an empty list by default?