Search code examples
sqlasp.net-mvcviewbag

MVC Viewbag correct Result count but displaying only item 1


Trying to use a viewbag on a create form (view) to let the user pick an "item" on the dropdown. The dropdown displays and shows correct number of rows (tested) but only displays the first item for the X number of rows. https://i.imgur.com/2179GTD.png "Image1"

Code of the view controller below as I didn't find any answers to this.

List<SelectListItem> Contracts = (from a in 
db.v_xxx_yyyy_aaaa_contracts.Where(m => m.GroupID.ToString() == 
@group).Distinct().OrderBy(a => a.ContractID).ToList()
                                              select new SelectListItem()
                                              {
                                                  Value = a.ContractID,
                                                  Text = a.ContractID
                                              }).ToList();

ViewBag.ContractID = Contracts;

Solution

  • The solution I found for this specific problem is found here!

    Had to bypass the viewmodel with ViewData (SelectList) for it to work as I wanted.