请帮助我解决 ASP.NET MVC 分页错误
当我执行分页功能 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这让我想起了 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 calledHasPreviousPage
, 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!
我认为您可能缺少名称空间导入。
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)
您需要更改控制器以使用分页,请查看 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
这里有几种可能性:
首先,模型是您的对象或类。 HasPreviousPage 是 Model 中的方法或函数。
以下是一些可能性:
我的猜测是它要么是一个布尔属性,要么是一个返回布尔值的方法。无论哪种方式,编译器都不知道如何处理它,因此您需要跟踪它。尝试在解决方案中查找“HasPreviousPage”。查看它是否在任何地方被引用,或者它位于何处。
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:
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.