1

I have been reading post such as this Cannot use NuGet PagedList ASP.NET MVC # View and articles such as this http://czetsuya-tech.blogspot.com/2011/05/mvc3-dynamic-search-paging-using.html but I can't get the paged list model to load in my View. It works in my controller, but the following code:

@ModelType PagedList.IPagedList(Of MyBlog.Company)

... Won't seem to work (i.e. I don't seem to have access to that PagedList class; it says it's not defined). What can I do to use PagedList? I even tried installing both PagedList and PagedList.MVC from NuGet, but still, nothing.

I am simply trying to complete this tutorial http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

It appears as though many have struggled with this particular aspect.

Thanks for your help.

Edit: This blog post describes my problem exactly:

http://www.1771.in/using-pagedlist-in-vb.html

There is no answer listed there, so maybe someone else knows what to do.

Community
  • 1
  • 1
user1477388
  • 20,790
  • 32
  • 144
  • 264

1 Answers1

2

OK, my VB.NET is kinda rusty but let's see what we can do here.

  1. Create a new ASP.NET MVC 3 application
  2. In the Package Manager Console type: Install-Package PagedList.Mvc to install the NuGet
  3. Add a model:

    Public Class MyViewModel
        Public Property Id As Integer
        Public Property Foo As String
    End Class
    
  4. Then update HomeController.vb:

    Imports PagedList
    
    Public Class HomeController
        Inherits System.Web.Mvc.Controller
    
        Function Index() As ActionResult
            Dim model = Enumerable.Range(1, 250).Select(Function(x) New MyViewModel With {.Id = x, .Foo = "foo " & x})
            Dim viewModel = model.ToPagedList(1, 5)
            Return View(viewModel)
        End Function
    End Class
    
  5. Finally define the Index.vbhtml view:

    @ModelType PagedList.IPagedList(Of MvcApplication1.MyViewModel)
    
    ...
    
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I did as you said; however, it still has a blue underline underneath of it when I add the @ModelType it says, "Type 'PagedList.IPagedList' is not defined." – user1477388 Aug 15 '12 at 20:05
  • There was an answer here "That did it. I removed the PagedList ref in MvcMembership, and referenced the PagedList project." https://github.com/TroyGoode/MembershipStarterKit/issues/23 But I don't know how to do as they say. – user1477388 Aug 15 '12 at 20:09
  • Did you do the simple steps outlined in my answer? Coz they work. – Darin Dimitrov Aug 15 '12 at 20:11
  • Yes, I believe so. I did them exactly but as soon as I get to the last step and paste @ModelType PagedList.IPagedList(Of MvcApplication1.MyViewModel), the blue line appears and says it's not defined. – user1477388 Aug 15 '12 at 20:12
  • That's hard to believe. I did those steps and it worked perfectly fine for me. So I guess you are not doing everything as I explained in my answer. I guess you are attempting to integrate this into some existing project. Did you do step `1.`? It's extremely important. – Darin Dimitrov Aug 15 '12 at 20:13
  • Wait, there's been a breakthrough, perhaps! I hit "build," then nothing at first. But now it has gone away [the blue line]. How can I make this work in my real project, now? – user1477388 Aug 15 '12 at 20:14
  • 1
    I have strictly no idea what you have in your real project so I cannot answer this question. But you could use my steps as a building foundation and progressively add the code from your project to enrich it and see when it stops working. This way you will be able to isolate the problem. You should always do this when you encounter a problem => try to isolate and narrow it down. Once you do this there are 2 possibilities: 1. either you immediately find out the solution or 2. you don't know and then post your detailed steps (as I did) on StackOverflow and hope someone to help you. – Darin Dimitrov Aug 15 '12 at 20:15
  • Thanks, Darin. It seems to be working in both places now, despite no changes having been made to the real site. I would appreciate any explanation you may be able to provide. – user1477388 Aug 15 '12 at 20:16
  • I know this is an older posting with an accepted answer, but I had the same exact problem and figured I would share what worked for me. I had to manually add a namespace reference for PagedList in the web.config file under the Views folder. Under the section add then rebuilt the solution and it worked. http://wp.sjkp.dk/asp-net-mvc5-easy-server-side-data-paging/ – Jonathan Moriarty Aug 05 '14 at 16:56