Adding a default SelectListItem

后端 未结 7 1235
一整个雨季
一整个雨季 2020-12-28 18:33
 public IEnumerable GetList(int? ID)
 {
      return from s in db.List
             orderby s.Descript
             select new SelectListItem
          


        
7条回答
  •  长发绾君心
    2020-12-28 19:01

    Here is what I did, I read my values from an XML file into an IList. I then inserted a new record into the IList at position 0. Then make a select list from the IList.

    IList< MY_DATA > mydata = (from tmp in myXML.Descendants("R").ToList()

                          select new MY_DATA
                          {
                             NR = tmp.Attribute("NR").Value,
                             NA = tmp.Attribute("NA").Value 
                          }).ToList();
    

    mydata.Insert(0, new My_DATA() { NR = "", NA = "--Click to Select--" });

    SelectList mylist = new SelectList(mydata, "NR", "NA");

提交回复
热议问题