Reputation: 639
I'm currently in the process of converting the MVC 2 portion of a hybrid Web Forms/MVC 2 application to MVC 3 (I'm not familiar with Web Forms or MVC 2) and have been encountering some problems with some of the foreach statements (which work fine in the original hybrid application).
When converting to Razor, some (not all) of my foreach statements will say something along the lines of:
foreach statement cannot operate on variables of type 'System.Data.Objects.DataClasses.EntityCollection<Project.Activity.PortalMember>' because 'System.Data.Objects.DataClasses.EntityCollection<Project.Activity.PortalMember>' does not contain a public definition for 'GetEnumerator'
This is an example .ascx from the Web Forms/MVC 2 application where the foreach works fine:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Project.Activity.PortalGroup>" %>
<% if (Model.PortalMembers.Count() > 0) { %>
<div>
<% foreach (var item in Model.PortalMembers) { %>
<div>
<%: item.SubAccount.FirstName %> <%: item.SubAccount.LastName %>
</div>
<%} %>
</div>
<%} %>
This is my attempt for the .cshtml conversion that is giving me the error:
@model Project.Activity.PortalGroup
@if (Model.PortalMembers.Count() > 0)
{
<div>
@foreach (var item in Model.PortalMembers)
{
<div>
@item.SubAccount.FirstName @item.SubAccount.LastName
</div>
}
</div>
}
Upvotes: 3
Views: 2763