0

我在我的视图中添加了模型:

    @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;
    }
4

1 回答 1

0

您应该使用 Text 和 Value 属性;

SelectList selectList = new SelectList(selectListItems, "Value", "Text");

于 2012-10-02T08:13:54.757 回答