请帮助我解决 ASP.NET MVC 分页错误

发布于 2024-08-11 16:42:59 字数 247 浏览 7 评论 0原文

当我执行分页功能 CS1061 时,我的 mvc 应用程序中出现以下错误

:“System.Collections.Generic.IEnumerable”不包含“HasPreviousPage”的定义,并且没有扩展方法“HasPreviousPage”接受类型的第一个参数可以找到“System.Collections.Generic.IEnumerable”(您是否缺少 using 指令或程序集引用?)

请告诉我要做什么以及该模型是什么。

I am getting the following error in my mvc application when I am doing the paging functionality

CS1061: 'System.Collections.Generic.IEnumerable' does not contain a definition for 'HasPreviousPage' and no extension method 'HasPreviousPage' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

please tell me what to do and what is that Model.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

从此见与不见 2024-08-18 16:42:59

这让我想起了 Conery 等人的 MVC 1.0 Wrox 书中的 PaginatedList 类...(也可能在 NerdDinner 应用程序中找到。)我实际上就在旁边有这本书。我并将此部分标记为选项卡。果然他们有一个名为 HasPreviousPage 的属性,这让我猜测这就是您正在使用的内容?它位于第 1 章中,可免费下载。 (谷歌搜索。)我强烈建议您看一下本章,或者至少看一下这一部分,因为还有许多其他有用的建议和技巧可以找到!

祝你好运!

This reminds me of the PaginatedList<T> class found in the Conery et al MVC 1.0 Wrox book... (And probably also found in the NerdDinner app.) I actually have this book right here next to me and have this section tabbed. And sure enough they have a property called HasPreviousPage, which leads me to guess this is what you are working with? It is in Chapter 1, which is a free download. (Google for it.) I highly recommend taking a look at this chapter, or at least this section, as there are many other helpful suggestions and tips to be found!

Best of luck!

吃兔兔 2024-08-18 16:42:59

我认为您可能缺少名称空间导入。

HasPreviousPage 是方法还是属性?如果它是您要返回的列表类型的辅助方法,那么您需要在您的 aspx 文件中导入该命名空间(或在 web.config 中以反映在所有页面上)

I think that you may be missing a namespace import.

Is HasPreviousPage a method or a property? If it is a helpermethod on the type of list you are returning then you need to import that namespace in your aspx file (or in the web.config to reflect on all pages)

清风不识月 2024-08-18 16:42:59

您需要更改控制器以使用分页,请查看 http://blogs。 embarcadero.com/johnk/2009/04/02/38871 了解更多信息

编辑:为了澄清,所以在控制器的某个地方,你会看到一些“return View(someModelObject)”效果的东西 - 你这里需要使用 PaginationHelper.AsPagination 将 someModelObject 转为可分页对象

You need to change the controller to use Paging, check out http://blogs.embarcadero.com/johnk/2009/04/02/38871 for more info

EDIT: To clarify, so somewhere in the Controller, you're gonna see something to the effect of "return View(someModelObject)" - you need to use PaginationHelper.AsPagination here to turn someModelObject into a pageable object

伴我老 2024-08-18 16:42:59

这里有几种可能性:

首先,模型是您的对象或类。 HasPreviousPage 是 Model 中的方法或函数。

以下是一些可能性:

  1. 模型未定义,因为文件未包含在页面中
  2. HasPreviousPage 不存在作为方法
  3. HasPreviousPage 实际上是一个属性,需要更多信息来提取数据(正如 tster 所说)
  4. HasPreviousPage 的签名不正确。您发送的数据过多或不足。

我的猜测是它要么是一个布尔属性,要么是一个返回布尔值的方法。无论哪种方式,编译器都不知道如何处理它,因此您需要跟踪它。尝试在解决方案中查找“HasPreviousPage”。查看它是否在任何地方被引用,或者它位于何处。

Ctrl + F
Find What: 
HasPreviousPage
Look In:
Entire Solution

There are a few possibilities here:

First off, Model is your object, or class. HasPreviousPage is a method or function in Model.

Here are some possibilities:

  1. Model is not defined because the file is not included in the page
  2. HasPreviousPage does not exist as a method
  3. HasPreviousPage is actually a property and needs more information to extract data (as tster is saying)
  4. The signature for HasPreviousPage is incorrect. You are sending too much, or not enough data.

My guess is it's either a boolean property, or a method that returns a boolean. Either way the compiler has no idea what to do with it, so you need to track it down. Try doing a find in your solution for "HasPreviousPage". See if it's been referenced anywhere, or where it is located.

Ctrl + F
Find What: 
HasPreviousPage
Look In:
Entire Solution
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文