foreach语句无法在类型为“变量操作”,因为“'不包含'的GetEnumerator'一个公共定义 [英] foreach statement cannot operate on variables of type '' because '' does not contain a public definition for 'GetEnumerator'

查看:2877
本文介绍了foreach语句无法在类型为“变量操作”,因为“'不包含'的GetEnumerator'一个公共定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了如下的错误
   说明:该请求提供服务所需资源的编译过程中出现错误。请检查下列特定错误详细信息并适当地修改源$ C ​​$ C。

I Got an Error Like This Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1579: foreach statement cannot operate on variables of type 'EventListing.Models.EventInfo' because 'EventListing.Models.EventInfo' does not contain a public definition for 'GetEnumerator'

Source Error:

Line 106:                </th>
Line 107:            </tr>
Line 108:            <% foreach (var model in Model)
Line 109:               { %>
Line 110:            <tr>

示范

public static List<EventInfo> EventList()
        {
            var list = new List<EventInfo>();
            Dbhelper DbHelper = new Dbhelper();
            DbCommand cmd = DbHelper.GetSqlStringCommond("SELECT * FROM WS_EVENTINFO");
            DbDataReader Datareader = DbHelper.ExecuteReader(cmd);
            while (Datareader.Read())
            {
                EventInfo eventinfo = new EventInfo()
                {
                    EVENT_ID = Convert.ToInt32(Datareader[

查看页

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<EventListing.Models.EventInfo>" %>
 <% foreach (var model in Model)
               { %>
            <tr>
                <td>
                    <%= Html.ActionLink(Model.TITLE,"Detail", new {id = Model.EVENT_ID})%>

如何解决这个问题,我使用MVC2框架。

How can solve this Issue, i'm Using MVC2 Framework.

推荐答案

presumably你正在尝试做的是:

Presumably what you are trying to do is:

 foreach(var model in Model.EventList()) {..}

虽然难以肯定。

如果您需要,那么你使用的语法模式将是一个类的对象用的GetEnumerator()方法。

If you require the syntax you used then Model will have to be an object of a class with a GetEnumerator() method.

这篇关于foreach语句无法在类型为“变量操作”,因为“'不包含'的GetEnumerator'一个公共定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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