I've googled this and tried so many different variations. I think the issue I'm having is there are so many ways to do this, and I'm not seeing the wood for the trees.
I have a list of equipment in a database. Each row is assigned to a company. There could be 10 pieces of equipment for company "Contoso Ltd", 23 pieces of equipment for "Geldof Industries" etc.
I have a scaffolded view using entity framework to display all the equipment for the entire database. This works fine.
What I want to do is have a dropdown list on the view, which populates with a list of distinct companies in the table and selecting a company then filters the results in the view.
At the moment my controller has this:
var serverList = from s in db.tbl_equipment
where (s.Company == "Contoso Ltd") && (s.Calc_Contract_Status == true)
where (s.Equip_type == "PC") || (s.Equip_type == "Laptop") || (s.Equip_type == "Mac") || (s.Equip_type == "Tablet") || (s.Equip_type.Contains("Server"))
select s;
return View(serverList.ToList());
As I understand it, I would populate a dropdown list based on a LINQ query, and use a viewbag to send that to the view then use a Dropdownlistfor html helper to create the dropdown. I'd assume I'd then need to capture the post request in someway back in the controller.
Every single site I have found for generating a dropdownlist in Razor and ASP.NET Entity Framework is different. Any help would be much appreciated!