开发者

Weird error in strongly-typed MVC2 view

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_1D9779ACB92AE24E3428C288EA开发者_JS百科7B1480A6477CF8861FB7582692E775613EFB3A', 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" />
<% } %>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜