15

我不能使用以下命名空间在视图的最顶部PagedList使用剃须刀 @model PagedList.IPagedList<PhoneBook.Models.Contact>Index.cshtml

我已经安装了 PagedList 并且我已经在我的控制器中使用了下面的代码

 using PagedList;

控制器页面没有错误,但为什么不能在 Index.cshtml(视图)中使用命名空间?请帮忙..

4

7 回答 7

23

BuildStarted 引用或存在于同时使用,

在控制器中

using PagedList;
using PagedList.Mvc;

并在视图中使用

@model PagedList.IPagedList<PhoneBook.Models.Contact>
@using PagedList;
@using PagedList.Mvc;

并使用分页

@Html.PagedListPager(Model, page => Url.Action("Index", new { page =
page }))
于 2012-05-18T15:06:50.553 回答
5

重新启动 Visual Studio 为我修复了它。

于 2014-10-22T20:10:41.123 回答
5

我刚刚发现了这个问题,因为我遇到了同样的问题。我已经阅读了许多建议使用这个 PagedList 对象的教程,但是没有一个说任何关于向 web.config 文件中添加任何内容的内容。这就是我为完成这项工作所做的。我使用了来自@BuildStarted 的评论中的一些信息。我正在使用VS2010。

将此添加到 web.config 文件中:

<add assembly="PagedList.Mvc" namespace="PagedList.Mvc" tagPrefix="plmvc"/>

所以它应该看起来像这样(剪断):

<configuration>
  <system.web>
    <pages ...>
      <controls>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
        **<add assembly="PagedList.Mvc" namespace="PagedList.Mvc" tagPrefix="plmvc"/>**
      </controls>
    </pages>
  </system.web>
</configuration>
于 2012-10-06T21:57:57.503 回答
3

当我使用@model 时,我遇到了同样的问题

PagedList.IPagedList

我得到错误:

PagedList.IPagedList<> 不包含...的定义。

解决方案 :

在 View -> Index.cshtml 中将
model.Code 替换为 model.First().Code

  • 只需在所有属性之前添加 First() 即可。
于 2015-06-17T13:54:20.840 回答
1

您需要在 bin/assembly 文件夹中添加参考。

于 2015-04-10T09:38:52.147 回答
1

我相信我遇到了完全相同的问题。Visual Studio 用红色强调 PagedList 并询问“您是否缺少 using 指令或程序集引用?”。

我所要做的就是构建项目。然后 Visual Studio 停止抱怨。

于 2014-04-03T14:18:46.003 回答
1

尝试在您的导入中使用非大写的“M vc ”,然后重新构建。

@using PagedList.Mvc;
//@using PagedList.MVC;
于 2015-12-10T09:53:55.000 回答