我正在关注Apress Pro Mvc 2 Framework书中的体育商店教程。错误:foreach语句无法对IENumerable类型的变量操作
自从我接触.net,我已经有一段时间了,而我对Mvc来说是全新的,而我已经落在第一个绊脚石!
我有以下错误:
foreach statement cannot operate on variables of type 'IENumerable' because 'IENumerable' does not contain a public definition for 'GetEnumerator'
下面是查看代码:)
公众的ViewResult列表( :
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IENumerable<SportsStore.Domain1.Entities.Product>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Products
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Products</h2>
<% foreach (var product in Model)
{ %>
<div class="item">
<h3><%: product.Name%></h3>
<%: product.Description%>
<h4><%: product.Price.ToString("c")%></h4>
</div>
<% } %>
</asp:Content>
这里是从控制器片段{} {返回View(productsRepository.Products.ToList()); }
这里是产品类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SportsStore.Domain1.Entities
{
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public string Category { get; set; }
}
}
我敢肯定,这有可能是一个简单的解决办法,但我跟着这本书正是这样略微恼怒,我犯了一个错误这么早上!
如果有人能帮助我,我会非常感激。
+1这本书! :-) – DaveDev 2010-10-29 22:54:05