views:

32

answers:

3

Hi guys,

I'm following the sportsStore tutorial from the Apress Pro Mvc 2 Framework book.

It's been a while since I touched .net, and I'm completely new to Mvc and I've fallen at the first stumbling block!

I have the following error:

foreach statement cannot operate on variables of type 'IENumerable' because 'IENumerable' does not contain a public definition for 'GetEnumerator'

Here is the code for the View:

<%@ 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>

Here is the snippet from the controller:

public ViewResult List() { return View(productsRepository.Products.ToList()); }

And here is the product class:

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

I'm sure this has probably a simple solution but I've followed the book exactly so slightly peeved that I've made a mistake so early on!

If anyone could help me out I'd be very grateful.

+3  A: 

Change IENumerable to IEnumerable.

SLaks
Perfect. Can't believe how silly that is!! Thanks a lot :) I'll mark this as correct once the time limit is up.
TaraWalsh
+1  A: 

Try IEnumerable not IENumerable.

Daniel A. White
+1  A: 

I think you have a typo. Use IEnumerable.

XSaint32