dropDownList不显示实际数据

时间:2012-10-02 08:05:18

标签: asp.net-mvc-3 asp.net-mvc-3-areas

我在我看来添加了模型:

    @model Tuple<List<EshopTheme.Areas.Administrators.Models.ThemeGroupsModel>,
                      EshopTheme.Areas.Administrators.Models.AdminModel,
                      EshopTheme.Areas.Administrators.Models.ThemesModel> 

在我的控制器中,我添加了此操作:

   public ActionResult AddTheme()
    {
        AdminSrv adminService = new AdminSrv();
        AdminModel adminModel = new AdminModel();
        ThemesModel themeModel = new ThemesModel();
        Tuple<List<ThemeGroupsModel>, AdminModel, ThemesModel> tuple =
            new Tuple<List<ThemeGroupsModel>, AdminModel, ThemesModel>
                (adminService.getAllThemeGroupByAdmin(), adminModel, themeModel);
        return View(tuple);
    }

我使用了这个DropDownListFor:

    @Html.DropDownListFor(x => x.Item1, new SelectList(Model.Item1))

但是,DropDownListFor显示了以下列表:

    EshopTheme.Areas.Administrators.Models.ThemeGroupsModel
    EshopTheme.Areas.Administrators.Models.ThemeGroupsModel
    EshopTheme.Areas.Administrators.Models.ThemeGroupsModel

为什么?????????????

这是我的getAllThemeGroupByAdmin()代码:

  public List<ThemeGroupsModel> getAllThemeGroupByAdmin()
    {
        List<ThemeGroupsModel> ThemeGr = new List<ThemeGroupsModel>();
        ThemeGroupsModel ThemeGrTemp;
        using (var context = new EShopThemeDBEntities(idbconnection.ConnStr))
        {
            var ThemeGroupList = (from o in context.ThemeGroups
                                  select o).ToList();

            foreach (var item in ThemeGroupList)
            {
                ThemeGrTemp = new ThemeGroupsModel();
                ThemeGrTemp.ThemeGroupName = item.ThemeGroupName;
                ThemeGrTemp.ThemeGroupId = item.ThemeGroupID;
                ThemeGr.Add(ThemeGrTemp);
            }
        }
        return ThemeGr;
    }

1 个答案:

答案 0 :(得分:0)

您应该使用Text和Value属性;

SelectList selectList = new SelectList(selectListItems,&#34; Value&#34;,&#34; Text&#34;);