paging in asp.net mvc

后端 未结 4 1615
忘掉有多难
忘掉有多难 2021-01-23 03:11

i have an asp.net website where i do paging through on the code behind using:

    PagedDataSource objPds = new PagedDataSource
                                 {         


        
4条回答
  •  梦谈多话
    2021-01-23 04:08

    I would just define a custom route with the page number in it:

    routes.MapRoute(
                    "Books", // Route name
                    "books/{page}", // URL with parameters
                    new {controller = "Books", action = "List", page = 1}
                    );
    

    Will give you this kind of Url:

    http://localhost/books/4/
    

    Then in your controller action you get this page number:

    public BooksController
    {
        public ActionResult List (int page)
        {
            /* Retrieve records for the requested page from the database */
    
            return View ();
        }
    }
    

    So your view will not actually be aware of the current page. It will just display a list of supplied records.

    You will also need to generate links to various pages either in this view directly or maybe in your master page.

提交回复
热议问题