寻呼asp.net的MVC [英] paging in asp.net mvc

查看:90
本文介绍了寻呼asp.net的MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net网站,我就在code翻阅使用背后:

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

	PagedDataSource objPds = new PagedDataSource
	                             {
	                                 DataSource = ds.Tables[0].DefaultView,
	                                 AllowPaging = true,
	                                 PageSize = 12
	                             };

什么是做传呼的asp.net-MVC相当于最佳途径。我认为,这将在视图code实际上属于

what is the equivalent best way of doing paging for asp.net-mvc. I would think this would actually belong in the view code.

推荐答案

我只想定义它的页码自定义路线:

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.

这篇关于寻呼asp.net的MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆