zoukankan      html  css  js  c++  java
  • Asp.Net Core 使用X.PagedList.Mvc.Core分页 & 搜索

    1.Nuget包添加引用: X.PagedList.Mvc.Core

    2.View: 

    @using VipSoft.Web.Model
    @model X.PagedList.IPagedList<VipSoft.Web.Model.DBEntity.Job>
    @using X.PagedList.Mvc.Core;
    
    
    <h1>社会招聘  职位搜索</h1>
    <form asp-action="JobInfo" method="get" class="form-inline" role="form">
        @Html.TextBox("searchKey", ViewData["SearchKey"] as string, htmlAttributes: new { @class = "form-control", placeHolder = "请输入职业关键词、背景专业名称" })
        <input type="submit" value="搜索" class="btn btn-primary" />
    </form>
    
    @foreach (var item in Model)
    {
        <div class="row m_t100">
            <div class="col-md-7">
                <p class="co_news_title m_t30">@item.Position</p>
                <p class="co_news_abstract m_t20">
                    所属部门: @item.Department  工作地点: @item.Locations
                    <br />
                    描述:@item.Description
                </p>
            </div>
        </div>
    }
    
    @Html.PagedListPager(Model, page => Url.Action("JobInfo", new { page, searchKey = ViewData["SearchKey"] }))

    3.Controller

    using X.PagedList;
    public IActionResult JobInfo(string searchKey, int page = 1, int pageSize = 10)
    {
        ViewData["PageSize"] = pageSize;
        ViewData["SearchKey"] = searchKey;
        List<Job> result = jobService.ListJob();  //可以把参数带到后台,我这边数据量小,直接全部全取在客户端分页的
        if (!string.IsNullOrEmpty(searchKey))
        {
            result = result.Where(s => (!string.IsNullOrEmpty(s.Position) && s.Position.Contains(searchKey))
                                       || (!string.IsNullOrEmpty(s.Locations) && s.Locations.Contains(searchKey))
                                       || (!string.IsNullOrEmpty(s.PositionType) && s.PositionType.Contains(searchKey))).ToList(); 
        }
        return View(result.ToPagedList(page, pageSize));
    }

     

  • 相关阅读:
    新浪微博千万级规模高性能、高并发的网络架构经验分享
    PHP- 如何在终端输出带颜色的字体?
    淘宝大秒杀系统是如何设计的?
    如何打造千万级Feed流系统
    Redis实现分布式锁 php
    Ubuntu16.04 安装PHP7 的 imagick 扩展
    nginx配置http访问自动跳转到https
    使用Redis来实现LBS的应用
    PHP多进程编程初步
    选redis还是memcache,源码怎么说
  • 原文地址:https://www.cnblogs.com/vipsoft/p/12891031.html
Copyright © 2011-2022 走看看