实际上,我需要将我的类的属性显示在 mvc 下拉列表中。我正在使用反射来获得这些东西。但现在我的问题是将它们作为键值对显示在下拉列表中。
我正在使用下面的代码...
public static Dictionary<string,string> SetProperties()
{
Type T = Type.GetType("Entity.Data.Contact");
PropertyInfo[] resultcontactproperties = T.GetProperties();
ViewContactModel viewobj = new ViewContactModel();
viewobj.properties = resultcontactproperties;
Dictionary<string, string> dic = new Dictionary<string, string>();
return dic;
}
那么如何将它们转换为字典以将它们放在下面的下拉列表中......?
@Html.DropDownListFor(m=>m.properties, new SelectList(Entity.Data.ContactManager.SetProperties(),"",""), "Select a Property")
Well this is my ViewContactModel
public class ViewContactModel
{
public List<Entity.Data.Contact> Contacts;
public int NoOfContacts { get; set; }
public Paging pagingmodel { get; set; }
public PropertyInfo[] properties { get; set; }
}
In the view I'm using this model