I want to make a dropdown list based on values from 2 columns, Id and Name, so I want it to be like <option value=Id">Name</option>, not just Name.
I can get just the names like so which is fine:
var result = from r in db.Categories
                         select r.Name;
            ViewBag.Categories = result;
@Html.DropDownListFor(model => model.Name, new SelectList(ViewBag.Categories), "Select Category")
But I want to have both ids and names as I already said, so I change my linq to be:
var result = from r in db.Categories
                         select new { r.Name, r.Id };
But I don't know how to make a dropdown with it with both id and name?