2016-11-15 62 views
-1

我想在動態下拉列表的末尾使用MVC C#添加額外選項名稱Other。當下拉菜單中加載數據時,在下拉列表的末尾總是會有一個額外的選項Other如何在動態下拉列表中添加額外選項列表末尾

public static List<SelectListItem> GetSubjects() { 
    try { 
     var subjectList = HelperMethods.ListofEntity<Subject>().Select(t => new SelectListItem { 
      Text = t.SubjectName, 
      Value = Convert.ToString(t.ID) 
     }).ToList(); 
     return subjectList; 
    } catch (System.Exception ex) { 
      throw ex; 
    } 
} 
+0

的只是將它加入 - 'subjectList.Add(新SelectListItem(){值= ....});' –

回答

0

您可以使用List<T>.Add()

subjectList.Add(new SelectListItem 
{ 
    Text = "Your Text", 
    Value = YourValue 
}); 
相關問題