本文介绍了无法将类型'ORS.DTO.GenderDTO'隐式转换为'System.Collections.Generic.IEnumerable'。存在显式转换(您是否错过了演员?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想填充表单数据库的dropdownlist但是会出现此错误...有人可以帮我解决此问题吗?无法将类型'ORS.DTO.GenderDTO'隐式转换为'System.Collections.Generic.IEnumerable' 。存在显式转换(您是否错过了演员表?)
i必须填充性别的下拉列表,并且必须获取存储在数据库中的值...
I wanted to populate the dropdownlistfor form database but this error is arises... Can Someone help me with this to remove this error Cannot implicitly convert type 'ORS.DTO.GenderDTO' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)
i have to populate dropdownlist for Gender and have to get values that are stores in the database...
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;
}
public class GenderDTO
{
public int ID { get; set; }
public string Description { get; set; }
public SelectList GenderList { get; set; }
}
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; }
}
推荐答案
model.GenderList = db.CAT_GENDER.ToList().Select(g => new SelectListItem { Text = g.Description, Value = g.ID });
-KR
-KR
GenderDTO model = new GenderDTO();
var gender = from g in db.CAT_GENDER
select g;
model.GenderList = new SelectList(gender, "ID", "Description");
List<genderdto> itms = new List<genderdto> ();
itms.Add(model);
return itms;</genderdto></genderdto>
这篇关于无法将类型'ORS.DTO.GenderDTO'隐式转换为'System.Collections.Generic.IEnumerable'。存在显式转换(您是否错过了演员?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!