MVC

1、安装控件

install-package Webdiyer.MvcPager

2、Cotroller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Huo.CMS.Web.Models;
using Webdiyer.WebControls.Mvc; namespace Huo.CMS.Web.Controllers
{
public class ArticleController : Controller
{
// GET: Article
public ActionResult Index(int pageIndex = , string search = "", string category = "", string date = "")
{
var query = from a in ArticleList.AsQueryable()
where a.Category.Equals(category)
select a;
var data = query.OrderByDescending(p => p.CreateDate).ToPagedList(pageIndex, );
if (Request.IsAjaxRequest())
{
return PartialView("_ArticleTable", data);
}
return View(data);
} private IList<VMArticle> ArticleList
{
get
{
List<VMArticle> list = new List<VMArticle>()
{
new VMArticle() {Category = "book",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "疯狂"},
new VMArticle() {Category = "book",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "端点"},
new VMArticle() {Category = "book",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "等等"},
new VMArticle() {Category = "book",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "单独"}, new VMArticle() {Category = "phone",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "苹果"},
new VMArticle() {Category = "phone",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "小米"},
new VMArticle() {Category = "phone",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "华为"},
new VMArticle() {Category = "phone",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "三星"}, new VMArticle() {Category = "soft",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "微软"},
new VMArticle() {Category = "soft",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "甲骨文"},
new VMArticle() {Category = "soft",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "谷歌"},
new VMArticle() {Category = "soft",CreateDate = DateTime.Now,Id=,ImagePath = "",Name = "稀有",Price = ,Title = "亚马逊"}, }; return list;
}
}
}
}

示例 Code

3、View

部分视图

@using Webdiyer.WebControls.Mvc
@model PagedList<Huo.CMS.Web.Models.VMArticle>
<div class="product-list">
@foreach (var item in Model)
{
<div class="product-item">
<a href="~/product/item?id=@item.Id">
<img src="@item.ImagePath" />
<h6>@item.Title</h6>
<span class="when">创建时间:@item.CreateDate.ToString("yyyy-MM-dd") @item.CreateDate.ToString("HH:mm")</span>
<span class="where">作者:@item.Name</span>
<span class="price">打赏:<h3>¥@item.Price</h3></span>
<span class="level">分类:@item.Category</span>
</a>
</div>
}
</div>
<div class="pagenav">
@Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "pageIndex", ContainerTagName = "div", CssClass = "", CurrentPagerItemTemplate = "<a href=\"#\" class='on'>{0}</a>", DisabledPagerItemTemplate = "<a class=\"disabled\">{0}</a>", PagerItemTemplate = "" }).AjaxOptions(a => a.SetUpdateTargetId("ProductList").SetDataFormId("searchForm"))
</div>

主视图

@using Webdiyer.WebControls.Mvc
@model PagedList<Huo.CMS.Web.Models.VMArticle>
@{
ViewBag.Title = "Index";
} <div class="container">
@using (Ajax.BeginForm("Index", "Article", new RouteValueDictionary { { "pageIndex", "" } }, new AjaxOptions { UpdateTargetId = "ProductList", HttpMethod = "Get", InsertionMode = InsertionMode.Replace }, new RouteValueDictionary { { "id", "searchForm" }, { "class", "form-inline well well-sm" } }))
{
<div class="searchform">
<input type="text" name="search" placeholder="搜索考试名称" />
<button type="submit" id="btn">搜索</button>
<input type="hidden" id="date" name="date" />
<input type="hidden" id="category" name="category" />
</div>
<div class="product-mod">
<div class="product-tool">
<span>默认排序</span>
<dl class="subjectBox">
<dt>分类:</dt>
<dd class="info" onclick="SetCategory('book', this)">书籍</dd>
<dd class="info" onclick="SetCategory('phone', this)">手机</dd>
<dd class="info" onclick="SetCategory('soft', this)">软件</dd>
</dl>
<dl class="timeBox">
<dt>时间分类:</dt>
<dd class="info1" onclick="SetDate('Week', this)">近一周</dd>
<dd class="info1" onclick="SetDate('Month', this)">近一月</dd>
<dd class="info1" onclick="SetDate('Year', this)">近一年</dd>
</dl>
</div>
</div>
}
<div id="ProductList">
@{ Html.RenderPartial("_ArticleTable"); }
</div> </div> @Scripts.Render("~/Scripts/MvcPager.js")
@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")
<script>
function SetDate(filter, ele) {
debugger;
var c = $(ele);
var b = c.hasClass("selected");
$(".info1", ".timeBox").removeClass("selected"); if (b) {
c.removeClass("selected");
$("#date").val("");
}
else {
c.addClass("selected");
$("#date").val(filter);
}
$("#btn").click(); }
function SetCategory(filter, ele) {
var c = $(ele);
var b = c.hasClass("selected");
$(".info", ".subjectBox").removeClass("selected"); if (b) {
c.removeClass("selected");
$("#category").val("");
}
else {
c.addClass("selected");
$("#category").val(filter);
}
$("#btn").click();
}
</script>

分页控件Webdiyer.MvcPager的更多相关文章

  1. .net分页控件webdiyer:AspNetPager

    首先下载:AspNetPager.dll   AspNetPager.xml  放到bin目录下 页面添加<%@ Register Assembly="AspNetPager" ...

  2. MvcPager 免费开源分页控件3.0版发布!

    MvcPager 3.0版在原2.0版的基础上进行了较大的升级,对MvcPager脚本插件重写并进行了大量优化.修复了部分bug并新增了客户端Javascript API等功能,使用更方便,功能更强大 ...

  3. MvcPager分页控件的使用

    1.引入MvcPager.dll(MvcPager分页控件:http://www.webdiyer.com/mvcpager/) 2.后台C# Controller: //Ddemo使用Webdiye ...

  4. MvcPager分页控件以适用Bootstrap

    随笔- 9  文章- 0  评论- 33  修改MvcPager分页控件以适用Bootstrap 效果(含英文版,可下载)   软件开发分页效果必不可少,对于Asp.Net MVC 而言,MvcPag ...

  5. MvcPager分页控件使用注意事项!

    初学MVC,做了个单页面应用,需要显示多个分页,并无刷新更新. 找到了MvcPager控件,非常好用,在使用ajax过程中遇到很多问题.慢慢调试和杨老师(MvcPaegr作者)请教,总于都解决了. 首 ...

  6. 开源mvcpager分页控件分页实例

    最近MVC需要用到分页,然后在网上找了一圈,发现一个很好用的分页控件,在此要感谢作者的辛勤劳动. 下载Pager 这个分页控件也有Asp.net的支持,需要的去看看作者的主页 webdiyer 先看看 ...

  7. 基于存储过程的MVC开源分页控件--LYB.NET.SPPager

    摘要 现在基于ASP.NET MVC的分页控件我想大家都不陌生了,百度一下一大箩筐.其中有不少精品,陕北吴旗娃杨涛大哥做的分页控件MVCPager(http://www.webdiyer.com/)算 ...

  8. MVC——分页控件

    不管是什么类型的网站,分页都是必不可少的功能实现.在这里记录一下我自己接触过的分页控件: 一. MvcPager控件(记得项目里添加MvcPager.dll的引用) 这里面比较常用的就 ——@Html ...

  9. 基于存储过程的MVC开源分页控件

    基于存储过程的MVC开源分页控件--LYB.NET.SPPager 摘要 现在基于ASP.NET MVC的分页控件我想大家都不陌生了,百度一下一大箩筐.其中有不少精品,陕北吴旗娃杨涛大哥做的分页控件M ...

随机推荐

  1. docker 实践四:仓库管理

    本篇我们来了解 docker 仓库的内容. 注:环境为 CentOS7,docker 19.03 仓库(Responsitory)是集中存放镜像的地方,又分公共仓库和私有仓库. 注:有时候容易把仓库与 ...

  2. spring cloud微服务实践七

    在spring cloud 2.x以后,由于zuul一直停滞在1.x版本,所以spring官方就自己开发了一个项目 Spring Cloud Gateway.作为spring cloud微服务的网关组 ...

  3. Python开发【第三章】:编码转换

    一.字符编码与转码 1.bytes和str 之前有学过关于bytes和str之间的转换,详细资料->bytes和str(第四字符串) 2.为什么要进行编码和转码 由于每个国家电脑的字符编码格式不 ...

  4. S03_CH13_ZYNQ A9 TCP UART双核AMP例程

    S03_CH13_ZYNQ A9 TCP UART双核AMP例程 13.1概述 ZYNQ中存在两个独立的ARM核,在很多应用场景中往往只需使用其中的1个核心即可.然而,对于复杂的设计,例如多任务,并行 ...

  5. Scratch运动模块——有趣的弹球游戏(一)

    大家好!我是蓝老师,有了前几期Scratch的基础,相信大家早已摩拳擦掌,跃跃欲试了,甚至还有些小伙伴已经编写了非常不错的程序. 学习编程就是这样不断探索.主动思考.解决问题的过程. 本期内容: 课程 ...

  6. (十二)Activitivi5之流程控制网关:排他

    一.概念 所谓排他网关 顾名思义 执行到该网关,根据条件只能走一条执行线 二.案例 当流程走到“学生请假”任务节点的时候, /** * 完成任务 */ @Test public void test_c ...

  7. (三十)JSP标签之自定义标签

    创建一个类,引入外部jsp-api.jar包(在tomcat 下lib包里有),这个类继承SimpleTagSupport 重写doTag()方法. jspprojec包下的helloTag类: 1 ...

  8. 数据仓库之抽取数据:通过openrowset执行存储过程

    原文:数据仓库之抽取数据:通过openrowset执行存储过程 在做数据仓库时,最重要的就是ETL的开发,而在ETL开发中的第一步,就是要从原OLTP系统中抽取数据到过渡区中,再对这个过渡区中的数据进 ...

  9. 组装技术的新进展 New advances in sequence assembly.

    组装技术的新进展 1.测序和组装 很难想象今天距离提出测序和组装已经有40年啦.我们回头来看一下这个问题. “With modern fast sequencing techniques and su ...

  10. SQL将同样标识的查询结果查重并用逗号拼接

    SELECT B.TaskID , LEFT(SamList, LEN(SamList) - 1) AS ResultListFROM ( SELECT TaskID , ( SELECT Sampl ...