.Net core Api后台获取数据,异步方法中,数据需采用Linq分页
.net core api


- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Cors;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.CodeAnalysis.CSharp.Syntax;
- using Microsoft.Extensions.Caching.Memory;
- using Weeko3_Test.BLL.IBLL;
- using Weeko3_Test.Model;
- namespace Weeko3_Test.Api.Controllers
- {
- [Route("api/Product")]
- [ApiController]
- [EnableCors("any")]
- public class ProductController : ControllerBase
- {
- /// <summary>
- /// 依赖注入
- /// </summary>
- private readonly IProductBll _bll;
- public ProductController(IProductBll bll)
- {
- _bll = bll;
- }
- [Route("SelectList")]
- [HttpGet]
- ////[EnableCors("any")]
- public async Task<PageViewModel> SelectList(int pageIndex = 1, int pageSize = 5)
- {
- List<ProductInfoModel> list = await Task.Run(() => { return _bll.Select(); });
- int count = list.Count;
- var v = list.Skip((pageIndex - 1) * pageSize).Take(pageSize);
- PageViewModel model = new PageViewModel();
- model.PageTotal = int.Parse(Math.Ceiling(decimal.Parse(count.ToString()) / pageSize).ToString());
- model.Models = v.ToList();
- return model;
- }
- }
- }
cshtml


- <link href="~/css/site.css" rel="stylesheet" />
- <script src="~/lib/jquery/dist/jquery.js"></script>
- <table class="layui-table" lay-size="sm">
- <colgroup>
- <col width="150">
- <col width="200">
- <col width="200">
- <col width="200">
- <col width="200">
- </colgroup>
- <thead>
- <tr>
- <th>产品名称</th>
- <th>投资金额</th>
- <th>投资收益</th>
- <th>投资时间</th>
- <th>投资编号</th>
- </tr>
- </thead>
- <tbody id="tb">
- </tbody>
- </table>
- <div>
- <div>
- <input id="btn_First" type="button" value="首页" />
- <input id="btn_Pro" type="button" value="上一页" />
- <input id="btn_Next" type="button" value="下一页" />
- <input id="btn_Last" type="button" value="尾页" />
- </div>
- </div>
- <script>
- var pageSize = 5;
- var pageIndex = 1;
- var count = 0;
- $(function () {
- Show();
- })
- function Show() {
- $.ajax({
- url: "http://localhost:51457/api/product/SelectList",
- type: "get",
- dataType: "json",
- data: { pageIndex: pageIndex, pageSize: pageSize },
- success: function (data) {
- count = data.pageTotal;
- $('#tb').empty();
- //循环遍历
- $.each(data.models, function (index, item) {
- //定义变量
- var tr = '';
- //开始拼接
- tr += '<tr class="active">';
- tr += '<td>' + item.product_Name + '</td>';
- tr += '<td>' + item.startMoney + '元' + '</td> ';
- tr += '<td>' + item.produce_ShouYi + '元' + '</td>';
- tr += '<td>' + item.tCreateDate + '</td> ';
- tr += '<td>' + item.product_No + '</td>';
- tr += '</tr>';
- //尾部添加
- $('#tb').append(tr);
- })
- }
- });
- }
- //首页
- $('#btn_First').click(function () {
- pageIndex = 1;
- Show();
- })
- //上一页
- $('#btn_Pro').click(function () {
- if (pageIndex - 1 < 1) {
- pageIndex = 1;
- alert("到顶了");
- } else {
- pageIndex--;
- Show();
- }
- })
- //下一页
- $('#btn_Next').click(function () {
- if (pageIndex + 1 > count) {
- pageIndex = count;
- alert("到底了");
- } else {
- pageIndex++;
- Show();
- }
- })
- //尾页
- $('#btn_Last').click(function () {
- pageIndex = count;
- Show();
- })
- </script>
.Net core Api后台获取数据,异步方法中,数据需采用Linq分页的更多相关文章
- ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案 try.dot.net 的正确使用姿势 .Net NPOI 根据excel模板导出excel、直接生成excel .Net NPOI 上传excel文件、提交后台获取excel里的数据
ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案 ASP.NET Core 从2.2版本开始,采用了一个新的名为Endpoint的路由方案,与原来的方案在使用上差别不 ...
- .NET Core API后台架构搭建
ASP.NET Core API后台架构搭建 项目文件:https://files.cnblogs.com/files/ZM191018/WebAPI.zip 本篇可以了解到: 依赖注入 Dapper ...
- [转载]JAVA获取word表格中数据的方案
上一个项目的开发中需要实现从word中读取表格数据的功能,在JAVA社区搜索了很多资料,终于找到了两个相对最佳的方案,因为也得到了不少网友们的帮助,所以不敢独自享用,在此做一个分享. 两个方案分别是: ...
- [原创]JAVA获取word表格中数据的方案
上一个项目的开发中需要实现从word中读取表格数据的功能,在JAVA社区搜索了很多资料,终于找到了两个相对最佳的方案,因为也得到了不少网友们的帮助,所以不敢独自享用,在此做一个分享. 两个方案分别是: ...
- 【记录】mybatis中获取常量类中数据
部分转载,已注明来源: 1.mybatis中获取常量类中数据 <update id="refuseDebt"> UPDATE dt_debt a SET ...
- python xlrd 模块(获取Excel表中数据)
python xlrd 模块(获取Excel表中数据) 一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了pyt ...
- MySQL查询数据表中数据记录(包括多表查询)
MySQL查询数据表中数据记录(包括多表查询) 在MySQL中创建数据库的目的是为了使用其中的数据. 使用select查询语句可以从数据库中把数据查询出来. select语句的语法格式如下: sele ...
- .Net NPOI 上传excel文件、提交后台获取excel里的数据
1.导入NPOI.dll 2.添加类NPOIExcel.cs using System; using System.Collections.Generic; using System.Text; us ...
- scrapy获取当当网中数据
yield 1. 带有 yield 的函数不再是一个普通函数,而是一个生成器generator,可用于迭代 2. yield 是一个类似 return 的关键字,迭代一次遇到yield时就返回yiel ...
随机推荐
- Java中this和super的使用
区别 区别点 this super 访问属性 访问本类中的属性,如果本类没有,则从父类继续查找 访问父类中的属性 调用方法 访问本类中的方法,如果本类没有,则从父类继续查找 直接访问父类的方法 调用构 ...
- 02 HTML标签
2. HTML标签 1. HTML简介 用户使用浏览器打开网页看到结果的过程就是:浏览器将服务端的文本文件(即网页文件)内容下载到本地,然后打开显示的过程. 而文本文件的文档结构只有空格和黄航两种组织 ...
- Solution -「多校联训」假人
\(\mathcal{Description}\) Link. 一种物品有 长度 和 权值 两种属性,现给定 \(n\) 组物品,第 \(i\) 组有 \(k_i\) 个,分别为 \((1,a ...
- LRU缓存及实现
一.淘汰策略 缓存:缓存作为一种平衡高速设备与低速设备读写速度之间差异而引入的中间层,利用的是局部性原理.比如一条数据在刚被访问过只有就很可能再次被访问到,因此将其暂存到内存中的缓存中,下次访问不用读 ...
- 【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
问题描述 App Service for Linux 资源创建完成后,通过FTP方式把 .jar包(logdemo.jar)包上传到 /site/wwwroot/ 文件夹后,在App Service的 ...
- MyBatis功能点二:从责任链设计模式的角度理解插件实现技术
MyBatis允许对其四大组件(Executor,StatementHandler,ParameterHandler, ResultSetHandler)进行增强处理.在创建四大组件对象的时候 1.每 ...
- 【转】浅谈 Integer 类
突然发现自己对Integer i = 10;这种语法不太明白,于是乎有了这篇文章,那么在讲解 Integer 之前,我们先看下面这段代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- ctf平台
CTF靶场 蓝鲸安全:http://whalectf.xin bugku:https://ctf.bugku.com XCTF攻防世界:https://adworld.xctf.org.cn/ i春秋 ...
- IPC$管道的利用与远程控制
实验目的 通过实验了解IPC$攻击的原理与方法. 实验原理 IPC$攻击的相关原理 IPC$(Internet Process Connection)是共享"命名管道"的资源,它是为了让进程间通信而开 ...
- 智能脚本工具(Smart scripts)测试应用
如果你是一位网络测试人员,您的工作中是否有出现过以下困扰呢? · 重复机械式的测试有时让你觉得工作是如此的枯燥乏味!· 只增不减的测试用例让你下班越来越晚!· 请求老板招人,人却永远不够用! 但值得庆 ...