MVC SelectList combining multiple columns in text field

前端 未结 5 1520
遇见更好的自我
遇见更好的自我 2020-12-04 19:12

How would I generate a select list, where the text field, is made up of two or more text columns, eg: Where I have a Description and Rate field in my database, I want to com

5条回答
  •  一个人的身影
    2020-12-04 19:45

    var stands = db.Stands.Where(s => s.ExhibitorID == null).ToList();
    IEnumerable selectList = from s in stands
                                             select new SelectListItem
                                                        {
                                                          Value = s.StandID,
                                                          Text = s.Description + "-- £" + s.Rate.ToString()
                                                        };
    ViewBag.StandID = new SelectList(selectList, "Value", "Text");
    

提交回复
热议问题