0
在SelectList下拉列表中,我喜歡如果Count爲1,我喜歡默認藥物列表中的值,在這種情況下,它只有1個值。我無法弄清楚如何做到這一點。 我有以下以下幾點:MVC SelectList下拉默認
var drugfamilylist = (from dt in DataContext.Drugs
select dt.Drugvalue).Distinct().ToList();
if (drugfamilylist.Count == 1)
{
ViewBag.DrugFamily = new SelectList(drugfamilylist);
}
我試過但IDD也不行:
var drugfamilylist = (from dt in DataContext.Drugs
select dt.Drugvalue).Distinct().ToList();
if (drugfamilylist.Count == 1)
{
ViewBag.DrugFamily = new SelectList(drugfamilylist,drugfamilylist);
}
目前還不清楚你想做什麼... –