如何在我的Ddl控件中默认进行选择 [英] How Do I Make Select By Default In My Ddl Control

查看:103
本文介绍了如何在我的Ddl控件中默认进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个字典,该字典绑定到具有按字母顺序选择的值的模型类..要设置选择"为默认值

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

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);
   }

推荐答案

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


-KR


-KR


这篇关于如何在我的Ddl控件中默认进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆