views:

46

answers:

1

The ViewUserControl below results in the following error at runtime: The Collection template was used with an object of type 'System.Data.Entity.DynamicProxies.Collection_1D9779ACB92AE24E3428C288EA7B1480A6477CF8861FB7582692E775613EFB3A', which does not implement System.IEnumerable.

The error occures on this line: <%: Html.EditorFor(model => model) %>

If I change the name of the model object to Collection2 it works. Does it gets confused because Collection is also the name of an object in the .net framework?

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CollectionManager.Models.Collection>" %>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true) %>

    <%: Html.EditorFor(model => model) %>

    <input type="submit" value="Save" />
<% } %>
A: 

remco - yes, i think that would definately be a reserved word. not sure about it getting confused but definately you should take care with naming when potential clashes could occur. the same thing is true of variable names, tho you can prefix them with @ to override that i.e. string @absract would be allowable, whereas string abstract wouldn't.

go with the 'reserved' flow :)

jim

jim
Thanks for your response. I'm gonna rename the Collection class to something else.
Remco Storm
Not saying the name 'Collection' isn't a problem, but I'm not sure this is as straightforward as you make it seem: "Collection" does not appear to be a *reserved word* in the .NET Framework. It's not even the name of a framework class, as far as I can tell: System.Collections.ObjectModel contains Collection<T>, and the abstract base class from System.Collections is called CollectionBase.Even if Collection were a framework class, you could still reference your own class with that name by prepending its fully-qualified namespace...
djacobson