Cannot use NuGet PagedList ASP.NET MVC # View

2019-03-12 13:51发布

I can't use the following namespace PagedList to use razor @model PagedList.IPagedList<PhoneBook.Models.Contact>in the topmost of view Index.cshtml

I already installed PagedList and i used already the code below in my Controller

 using PagedList;

there's no error in the controller page but why ican't use the namespace in Index.cshtml (View)? Please help..

7条回答
叼着烟拽天下
2楼-- · 2019-03-12 13:53

I just found this question because I was having the same problem. I have read through many tutorials suggesting the use of this PagedList object, but none of them said anything about adding anything to the web.config file. This is what I did in order to make this work. I used some of the info from the comment from @BuildStarted. I am using VS2010.

Add this to the web.config file:

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

So it should look like this (snipped):

<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>
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-03-12 13:53

I had the same issue, when I'm using @model

PagedList.IPagedList

I get error :

PagedList.IPagedList<> does not contain a definition for ....

Solution :

In View -> Index.cshtml
Replace model.Code with model.First().Code

  • Just Add First() before all properties.
查看更多
欢心
4楼-- · 2019-03-12 13:56

Restarting Visual Studio fixed it for me.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-03-12 13:56

you need to add reference in your bin/assembly folder.

查看更多
The star\"
6楼-- · 2019-03-12 14:01

Try using a non-capitalised "Mvc" in your imports and then rebuild.

@using PagedList.Mvc;
//@using PagedList.MVC;
查看更多
你好瞎i
7楼-- · 2019-03-12 14:06

BuildStarted referral or existing on at the same time use,

in controller

using PagedList;
using PagedList.MVC;

and use in view

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

and use paging

@Html.PagedListPager(Model, page => Url.Action("Index", new { page =
page }))

Sorry for bad English is.

查看更多
登录 后发表回答