Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a dictionary which is binding to a model class with the selected values in alphabetical order .. In want to set "Select" as default value

C#
private IDictionary<int, String> GetAvailableHomeTypes()
   {
       var includeHomeTypes = new List<int>
                                 {
                                     (int)HomeType.New,
                                     (int)HomeType.Lease,
                                     (int)HomeType.Rent,
                                     (int)HomeType.RentWithLease,
                                     (int)HomeType.Apartment,
                                     (int)HomeType.Other
                                 };
       return ModelProviderFactory.Get<IInfoModelProvider>().GetInfo(InfoObjectType.HomeTypeInfo)
                                  .Where(HomeTypeInfo=> includeHomeTypes.Contains(HomeTypeInfo.Key))
                                  .ToDictionary(HomeTypeInfo=> HomeTypeInfo.Key, HomeTypeInfo=> HomeTypeInfo.Value);
   }
Posted
Comments
F-ES Sitecore 28-Oct-15 8:19am    
Google for "mvc dropdown example", there are many examples of how to bind to dropdowns.

1 solution

In view,
HTML
@Html.DropDownListFor(model => someId, 
                      new SelectList(yourDropDownCollection, "ID", "Name"),
                      "== Select ==")

-KR
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900