我得到了一个错误"有型的没有ViewData的项目'的IEnumerable< SelectListItem>' [英] I got an error "There is no ViewData item of type 'IEnumerable<SelectListItem>'

查看:164
本文介绍了我得到了一个错误"有型的没有ViewData的项目'的IEnumerable< SelectListItem>'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误有型无ViewData的项目'的IEnumerable具有关键TIMEZONE'。

I got an error "There is no ViewData item of type 'IEnumerable' that has the key 'TIMEZONE'".

查看

        <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<EventListing.Models.EventInfo>" %>               
        <%= Html.DropDownList("TIMEZONE", (IEnumerable<SelectListItem>)ViewData["TIMEZONE"], "Select Timezone")%>

控制器

ViewData["TIMEZONE"] = new SelectList(EventModel.getTIMEZOMES, "Key", "Value");
return View();

示范页

public static IList<KeyValuePair<string, string>> getTIMEZOMES
        {
            get
            {
                Dbhelper DbHelper = new Dbhelper();
                IList<KeyValuePair<String, String>> Timezone = new List<KeyValuePair<String, String>>();
                DbCommand cmd = DbHelper.GetSqlStringCommond("SELECT * FROM TMP_TIMEZONES");
                DbDataReader Datareader = DbHelper.ExecuteReader(cmd);
                while (Datareader.Read())
                {
                    Timezone.Add(new KeyValuePair<String, String>(Datareader["ABBR"].ToString(), Datareader["NAME"].ToString()));
                }

                return Timezone;
            }
        }

PLZ给予解决。

Plz Give the solution.

推荐答案

一个可能的原因是,在控制器中,你可能不会得到该数据到计算机[时区] 。尝试调试它,看看你得到什么。

One possible reason could be, In the controller, you may not be getting the data into the ViewData["TimeZone"]. Try to debug it and see what you are getting.

这篇关于我得到了一个错误&QUOT;有型的没有ViewData的项目'的IEnumerable&LT; SelectListItem&GT;'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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