///
/// List转SelectListItem
///
/// Model对象
/// 集合
/// 显示值-属性名
/// 显示值-属性名
///
///
public static List CreateSelect(IList t, string text, string value,string empId)
{
List l = new List();
foreach (var item in t)
{
var propers = item.GetType().GetProperty(text);
var valpropers = item.GetType().GetProperty(value);
l.Add(new SelectListItem
{
Text = propers.GetValue(item, null).ToString(), Value = valpropers.GetValue(item, null).ToString(),
Selected = valpropers.GetValue(item, null).ToString() == empId
});
}
return l;
}
List list = LoadData();
List emplist = CreateSelect(list, "EmpName", "EmpId",entity.HrEmpGuid.ToString());
ViewData["Emp"] = new SelectList(emplist, "Value", "Text");