I thinks is not so nice to use ViewBag to populate dropdowns in mvc. You shoud change you model to have a list of SelectedListItem and populate it from list of PriceList so it should look like this :
public class Model
{
public int CustomerID { get; set; }
public int SelectedCustomer { get; set; }
public IList<Pricelist> PriceList{get;set;}
public IList<SelectListItem> PriceListSelectListItem{get;set;}
{
get
{
var list = (from item in PriceList
select new SelectListItem()
{
Text = item.customerID.ToString(CultureInfo.InvariantCulture),
Value = item.selectedCustomer.ToString(CultureInfo.InvariantCulture)
}).ToList();
return list;
}
set{}
}
}
and now in view you will be able to do something like this :
@Html.DropDownListFor(c=>c.CustomerID,Model.PriceList)
Try to use dropdown like this, this will look more profesional than using ViewBag in views.
Controller:
var query = ((from s in db.Pricelists
select s.CustId).Distinct()).ToList();
int i = 1;
List<Pricelist> CustomerList = new List<Pricelist>();
foreach (var c in query)
{
int cust = c;
Pricelist p = new Pricelist(i, cust);
CustomerList.Add(p);
i++;
}
model.PriceList=result of your query
return View("ViewName",model);