.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 Calendar
Calendar是Java util包下的日期Api,其中获取月份是当前月份-1 public class Demo { public static void main(String[] args) ...
- 基于TI DSP TMS320C6455、Xilinx V5 FPGA XC5VSX95T的高速数据处理核心板
一.板卡概述 该DSP+FPGA高速信号采集处理板由我公司自主研发,包含一片TI DSP TMS320C6455和一片Xilinx V5 FPGA XC5VSX95T-1FF1136i.包含1个千兆网 ...
- Solution -「FJWC 2020」人生
\(\mathcal{Description}\) OurOJ. 有 \(n\) 个结点,一些结点有染有黑色或白色,其余待染色.将 \(n\) 个结点染上颜色并连接有向边,求有多少个不同(结点 ...
- CPU使用率过高怎么办
实际上前文中关于CPU使用率过高如何通过各种工具获得相关的热点进程.那么进程有了,那得疑惑到底哪个哪段代码导致了这个进程成为热点呢? 如果在调试阶段,可以使用gdb中断运行,但是在生产环境肯定不行.L ...
- spring循环依赖的产生与解决
1.循环依赖的产生 在spring中对象默认都是单例的 ,意味整个容器中只有一个该类的对象. 如图,B类有一个属性a,A类有一个属性b.当B类创建对象时,要给a属性赋值:当A类创建对象时,要给b属性赋 ...
- pytest(5)-断言
前言 断言是完整的测试用例中不可或缺的因素,用例只有加入断言,将实际结果与预期结果进行比对,才能判断它的通过与否. unittest 框架提供了其特有的断言方式,如:assertEqual.asser ...
- python-利用faker模块生成测试数据
Python-利用faker模块生成测试数据 1.前言: Faker模块是一个生成伪数据的第三方模块,他提供了一系列方法,使用非常方便,在做自动化测试时,注册信息,用这个模块生成测试数据就体现了它的好 ...
- NSSCTF-[SWPU 2020]找找吧
下载附件得到一个rar的压缩包,解压是需要密码的,直接丢尽winhex(菜狗经验),在最下面可以看到一个KEY is 得到第一个压缩包的密码,解压第一个压缩包得到一个mp3文件和另一个rar压缩包,将 ...
- HMS Core在MWC2022展示最新开放能力,助力开发者构建精品应用
[2022年2月28日,巴塞罗那]世界移动通信大会MWC2022在巴塞罗那开幕.HMS Core设立了3个展台(Fira Gran Via,Hall 1),向全球开发者展示HMS Core 6的全新开 ...
- 如何在win server中更改服务器密码长度最小值
转至:https://jingyan.baidu.com/article/3aed632e65c7843111809122.html windows server 2008是一种服务器的操作系统,有较 ...