実際には、クラスのプロパティを 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