1

I'm trying to create a strongly typed partial view

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"     Inherits="System.Web.Mvc.ViewPage<IEnumerable<Pt.Data.Services>>" %>
<table>
  <% foreach (Pt.Data.Services item in Model)
       { Html.RenderPartial("ServiceItem",item); } %>
</table>

in the Controller:

IEnumerable<Services> Model=null;
using (tl ctx = new tl(Config.ConnectionString))
{
    Model = ctx.Services.ToList();
}
return View("List",Model);

This workied well when running in a project with the binary assembly System.Web.Mvc referenced.

But if I remove binary assembly and add a project with MVC sources for debugging, it stops recognizing strongly typed views.

It's working like a ViewPage instead of ViewPage<TModel>

As result I'm getting the error:

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

Why would this work with the compiled MVC, but not with the sources? And how can I make the sources run correctly?

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
bug0r
  • 613
  • 1
  • 8
  • 19

2 Answers2

4

Have you changed this line in ~/Views/Web.config:

<pages validateRequest="false"
       pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter,
                             System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
                             PublicKeyToken=31BF3856AD364E35"
       pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0,
                     Culture=neutral, PublicKeyToken=31BF3856AD364E35"
       userControlBaseType="System.Web.Mvc.ViewUserControl,
                            System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
                            PublicKeyToken=31BF3856AD364E35">

to this?:

<pages validateRequest="false"
       pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter,
                             System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
                             PublicKeyToken=NULL"
       pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0,
                     Culture=neutral, PublicKeyToken=NULL"
       userControlBaseType="System.Web.Mvc.ViewUserControl,
                            System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
                            PublicKeyToken=NULL">

Actually this Steve Sanderson's post might be helpful

eu-ge-ne
  • 28,023
  • 6
  • 71
  • 62
  • No, I didn't set PublicKeyToken to NULL. Really, it can help. I will try now. – bug0r May 22 '09 at 15:59
  • This has not worked for me. I was not able to find the View anymore – Julien Nephtali Jun 12 '09 at 13:45
  • 1
    In case you updated the MVC framework version (by changing web.config files and references manually), you also need to change these version strings to e.g. 3.0.0.0 (for MVC 3). – AndiDog Nov 18 '11 at 16:41
0

I don't know of a reason that might cause a referenced source project to behave differently than its own build output(assembly). Still I can recommend:
1- Make sure the source you're using is the same the assembly was built off.
2- Make sure you added a reference to the source project.
3- RC on your solution file, choose clean solution, then rebuild and try again.

Ahmed
  • 11,063
  • 16
  • 55
  • 67
  • no positive result. I guess maybe the reason is in compilation of MVC. Compiled sources in release mode has a size of 179 712 bytes But binary assembly from MVC release has a size of 186 176 bytes Looks like some of generic classes are not compiled or something like that. – bug0r May 21 '09 at 11:06