. NET MVC Paging

Source: Internet
Author: User
Tags httpcontext

1. Pagination Entity class

    public class Pagedto    {public        int PageIndex {get; set;}        public int PageSize {get; set;}        public int PageCount {get; set;}        public int TotalCount {get; set;}    }

Back-end Code

        Public async task<iactionresult> Index ()        {            var page = httpcontext.request.query["page"]. ToString ();            var pageSize = httpcontext.request.query["PageSize"]. ToString ();            var searchdto = new Filesearchdto ()            {                PageIndex = string. Isnullorwhitespace (page)? 1:convert.toint32 (page),                PageSize = string. Isnullorwhitespace (pageSize)? 5:convert.toint32 (pageSize)            };            var results = await _service. Getpagelist (searchdto);            var model = new Filelistviewmodel () {Results = Results};            return View (model);        }


2. View

@using System.Text; @model baseservice.pagedto@if (Model.totalcount > Model.pagesize) {var controller = Url.actioncon Text.    routedata.values["Controller"];    var action = url.actioncontext.routedata.values["Action"];    var url = "/" + controller + "/" + action;    var querys = Url.ActionContext.HttpContext.Request.Query;    StringBuilder sb = new StringBuilder (); Sb.    AppendFormat ("/{0}/{1}?", controller, action); if (Querys! = null && querys. Count > 0) {foreach (var item in Querys) {if (!item. Key.equals ("page")) {sb. AppendFormat ("{0}={1}", item. Key, item.                Value); Sb.            Append ("&"); }}} sb.    Append ("page"); url = sb.    ToString ();            <div style= "position:fixed;bottom:-15px;text-align:center;width:84%" > <ul class= "Pagination" > 

3. Call

@Html. Partial ("~/views/pager/create.cshtml", Model.Results.Page)

. NET MVC Paging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.