Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3953598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:59:38+00:00 2026-05-20T01:59:38+00:00

I have looked at the Subsonic 5 Minute Demo, and got my data objects

  • 0

I have looked at the “Subsonic 5 Minute Demo”, and got my data objects generated from the database after some initial problems. I am using Visual Web Developer Express 2010 and my project is, as in the demo, an ASP.NET MVC 2 Web Application.

So, I’ve written this code in my HomeController:

public ActionResult Index()
{
    ViewData["Message"] = "Welcome to Food Recipe Web!";

    //lets get some data
    var db = new FoodRecipeWeb.Data.FoodRecipeWebDB();
    var recipes = from r in db.Recipes
                  select r;

    return View(recipes);
}

My View looks like this:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%: ViewData["Message"] %></h2>
    <ul>
    <%foreach (var recipe in Model)
      { %>

      <li><%= recipe.Name %></li>

    <% } %>
    </ul>
</asp:Content>

This is quite like the demo, but when I try to look at the page, I get this message:

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

Source Error:
Line 6:      <h2><%: ViewData["Message"] %></h2>
Line 7:      <ul>
Line 8:      <%foreach (var recipe in Model)
Line 9:        { %>
Line 10: 

So what am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:59:39+00:00Added an answer on May 20, 2026 at 1:59 am

    Your View needs to know about the Model.

    Change it from:

    Inherits="System.Web.Mvc.ViewPage"
    
    Inherits="System.Web.Mvc.ViewPage<IEnumerable<Recipe>>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some accesses from 192.168.0.71 on my apache logs. I looked up this
I have looked over the Repository pattern and I recognized some ideas that I
I have looked at some resources to tell me how -> and . are
I have looked at the SQL Server 2008 feature comparison matrix and it lists
I have looked at NHibernate and EntitySpaces and they both seem to work differently.
I have looked on FaceBook Developer page and found that it's possible to create
I have looked around on the Internet trying to answer this question. It seems
I have looked all of the place for this and I can't seem to
I have looked at the Suggested related questions but none of them are what
I've used jdom in the past, and have looked briefly at XOM and DOM4j

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.