【问题标题】:error CS1061: 'object' does not contain a definition for PageCount错误 CS1061:“对象”不包含 PageCount 的定义
【发布时间】:2014-08-07 07:41:12
【问题描述】:

我迁移了opensurce项目

http://surveymaster.codeplex.com

从 MVC 2 到 MVC 4

我现在有以下编译错误:

c:\inetpub\wwwroot\Views\SurveySession\Index.aspx(7,13): error CS1061: 'object' does not contain a definition for 'PageCount' and no extension method 'PageCount' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) 
c:\inetpub\wwwroot\Views\SurveySession\Index.aspx(12,38): error CS1061: 'object' does not contain a definition for 'Page' and no extension method 'Page' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
c:\inetpub\wwwroot\Views\SurveySession\Start.aspx(22,34): error CS1061: 'object' does not contain a definition for 'SurveyId' and no extension method 'SurveyId' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
c:\inetpub\wwwroot\Views\SurveySession\Start.aspx(23,30): error CS1061: 'object' does not contain a definition for 'Questions' and no extension method 'Questions' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
c:\inetpub\wwwroot\Views\SurveySession\Review.aspx(23,34): error CS1061: 'object' does not contain a definition for 'SessionId' and no extension method 'SessionId' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

第 7 行给出了错误:

Line 5:  </asp:Content>
Line 6:  <asp:Content runat="server" ID="Content1" ContentPlaceHolderID="MainContent">
Line 7:  <% if(Model.PageCount.Equals(0)) {%>
Line 8:  La moment nu sunt chestionare disponibile pentru dvs.
Line 9:  <%}%>

如果需要,还有源码完整编译源

【问题讨论】:

  • 你有一个名为 PageCount 的模型属性???
  • 对不起,我是一个初学者,模型属性是这个截图右边的吗? db.tt/BH3WjnGH
  • 没有具有 PageCount 名称的属性,这就是错误即将到来的原因..@carni89..
  • @carni89....如果答案可以帮助您解决问题,请点赞接受答案,这样它也可以帮助其他人..thankzzz...
  • 您是否尝试过构建和运行未修改的解决方案?

标签: asp.net-mvc migration codeplex


【解决方案1】:

查看您的第二张图片,您似乎缺少 Assembly Core.Model 中的一些类。您所指的视图使用Core.Model.IPageable&lt;Core.Model.SurveySession&gt;,但您似乎没有在Model.Core 中包含SurveySession.cs。检查source code 以确保包含所有必需的文件和参考。

注意:当时在 MVC 2 中使用 ASP 服务器控件可能被认为是不好的做法。在 MVC 4 中使用它们非常糟糕,我强烈建议您从头开始。

【讨论】:

  • 我在这里只搜索了 Pagecount 元素 dl.dropboxusercontent.com/u/17360312/pagecount.png 所以你看不到 SurveySession.cs。这里db.tt/8tdzM99j可以看到Model.Core的所有类
  • 您的错误 ..'object' does not contain a definition for 'PageCount'.. 表明模型没有被正确引用 - 特别注意 ..您是否缺少 using 指令或程序集引用?。恐怕如果不查看整个代码和所有参考资料,我就无法准确判断问题出在哪里。抱歉,我没有时间这样做。
  • surveymaster 中没有 ASP 服务器控件
  • @carni89 如果您使用网络表单视图引擎和母版页,您将拥有 asp:Content 但不使用 asp:Button 、标签等控件。
【解决方案2】:

在 Views/Web.config 文件中替换所有出现的

System.Web.Mvc, Version=2.0.0.0

System.Web.Mvc, Version=4.0.0.0

【讨论】:

    【解决方案3】:

    错误即将到来,因为您的模型类中没有名称为 PageCount 的属性,并且在名为 PageCount 的 MVC 中没有任何帮助程序或 extenstion methods 存在,只需在您的模型类中包含 PageCount 属性或从您的视图中删除此行,错误将被删除。

    谢谢!!

    【讨论】:

    • 它仍然不起作用..我将 PageCount 添加到我拥有的两个模型文件夹中 db.tt/OuNBs5Qn
    • @carni89.. 而不是创建另一个类,只需在现有类中添加一个属性 PageCount...
    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 2023-03-20
    • 2018-04-11
    • 1970-01-01
    • 2020-12-31
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多