16

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..

Jed
  • 1,664
  • 8
  • 33
  • 65
  • 2
    you should put the assembly references in your `web.config` under the `Views` folder. http://stackoverflow.com/a/3876409/365526 – Buildstarted May 18 '12 at 14:32
  • You can check my posted answer answer [here](http://stackoverflow.com/a/35433864/1148691) – mercu Feb 16 '16 at 13:42

7 Answers7

24

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 }))
Diego Venâncio
  • 5,698
  • 2
  • 49
  • 68
B. Bilgin
  • 774
  • 12
  • 22
5

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>
WMIF
  • 425
  • 4
  • 10
  • Nice. But also look at this answer. It helped me in VS2012 MVC4.5 - No idea why Nuget did not auto add it... I had to do it manually. – Piotr Kula Oct 13 '13 at 12:37
5

Restarting Visual Studio fixed it for me.

Tosh
  • 531
  • 7
  • 3
3

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.
MoniR
  • 1,351
  • 12
  • 18
1

I believe I had exactly the same problem. Visual Studio underlines PagedList in red and asks "are you missing a using directive or assembly reference?".

All I had to do was build the project. Then Visual Studio stops complaining.

1

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

Ashutosh Adarsh
  • 79
  • 1
  • 1
  • 9
  • I had this same issue, I had to uninstall PagedList.Mvc and reinstall it because PagedList was in my references, but not PagedList.Mvc... Weird. – JGTaylor Oct 30 '15 at 17:25
1

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

@using PagedList.Mvc;
//@using PagedList.MVC;