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 641035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:01:09+00:00 2026-05-13T21:01:09+00:00

I am currently using ASP.NET MVC 2.0 RC2, having recently moved from version 1.0.

  • 0

I am currently using ASP.NET MVC 2.0 RC2, having recently moved from version 1.0.

I have noticed that some of my views no longer work. I have views that inherit from a strongly-typed IEnumerable, like this:

Inherits="System.Web.Mvc.ViewPage<IEnumerable<MyProject.Models.MyType>>"

In the past, I have enumerated the model in my view like this:

<% foreach (var item in Model) { %>

But that no longer works. I get an error in the browser:

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

I can fix it by performing the requisite casts:

<% foreach (MyType item in (IEnumerable<MyType>)Model) { %>

But this is pretty ugly, and it suggests that there has been a change in behavior, so I need to know why.

I checked, and ViewPage.Model is indeed defined as object, so I’m wondering how this could have ever worked the way it did before. It’s also defined as object in ASP.NET MVC 1.0.

What gives?

Note: I have the MVC source code loaded into my project. Would that make a difference? Is there some metadata that gets injected at runtime that makes this work, which is prevented from doing so by seeing the object definition in the source?

  • 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-13T21:01:09+00:00Added an answer on May 13, 2026 at 9:01 pm

    FWIW, ViewPage.Model is of type TModel in ViewPage<TModel>, the generic class that you’re using. (In your sample code, TModel is IEnumerable<MyProject.Models.MyType>). So it shouldn’t be straight object.

    Does it make a difference if you change your @Page to

    Inherits="System.Web.Mvc.ViewPage<IEnumerable<MyType>>"
    

    and add a

    <%@ Import namespace="MyProject.Models" %>
    

    line to the view?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently creating an e-commerce site using C# ASP.NET MVC and have just
I have a ASP.Net 2.0 website that is currently using a custom MembershipProvider and
I have a site that I am currently working on in ASP.NET 2.0 using
Im currently using vs2008 with asp.net mvc framework for web development. Im missing a
I am currently building an application using ASP.NET MVC. The data entry pages are
I'm currently using Subversion to manage my ASP.NET website. I'm finding that whenever I
I am currently using asp.NET MVC to build a Content Management System parts of
I am currently develope something using asp.net MVC, im still quite not experience with
I'm currently developing an image viewer using asp.net MVC. The image viewer itself works
I'm wondering about a best practice using NHibernate, AutoMapper and ASP.NET MVC. Currently, i'm

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.