我想填充dropdownlistfor形式的數據庫,但這個錯誤是發生...有人可以幫助我消除這種誤差如何返回IEnumerable的<GenderDTO> GetGenderList()
無法隱式轉換類型「ORS。 DTO.GenderDTO'改爲'System.Collections.Generic.IEnumerable'。一個顯式轉換存在(是否缺少強制轉換?)
我有下拉列表填充性別和必須讓那些在數據庫中存儲的值...
public IEnumerable<GenderDTO> GetGenderList()
{
GenderDTO model = new GenderDTO();
var gender = from g in db.CAT_GENDER
select g;
model.GenderList = new SelectList(gender, "ID", "Description");
return model;
}
GenderDTO類
public class GenderDTO
{
public int ID { get; set; }
public string Description { get; set; }
public SelectList GenderList { get; set; }
}
CAT_GENDER
public partial class CAT_GENDER
{
public CAT_GENDER()
{
USER_PROFILE = new HashSet<USER_PROFILE>();
}
public int ID { get; set; }
[Required]
[StringLength(50)]
public string DESCRIPTION { get; set; }
public int STATUS_ID { get; set; }
public virtual CAT_RECORD_STATUS CAT_RECORD_STATUS { get; set; }
public virtual ICollection<USER_PROFILE> USER_PROFILE { get; set; }
}