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. sql复合索引使用和注意事项

    1.定义: 单一索引: 单一索引是指索引列为一列的情况,即新建索引的语句只实施在一列上; 复合索引: 复合索引也叫组合索引: 用户可以在多个列上建立索引,这种索引叫做复合索引(组合索引). 复合索引在 ...

  2. 《Mysql - 索引(唯一索引和普通索引的选择)Change Buffer 》

    一:概述 - 如果业务代码已经保证了不会写入重复的身份证号. - 从性能的角度考虑,你会为这个身份证号,选择唯一索引还是普通索引呢?选择的依据是什么呢? - 这就要从他们的执行过程看起. 二:唯一索引 ...

  3. consul 初体验

    consul server: 192.168.48.134: #!/bin/bash cd /data/server/consuls nohup /data/server/consuls/consul ...

  4. 网络模式: host-only & NAT & 桥接

    基本上,Host-only相当于虚拟机和宿主机通过交叉线相连:NAT,宿主机相当于虚拟机的路由器:桥接,相当于把宿主机和虚拟机同时接到交换机上,然后交换机接到外网. 连接性上说,可参考下表: 连接 宿 ...

  5. 定义别名:typedef和using

    定义别名:

  6. 15_IO流

    IO流 流 流的概念 流(stream)是指一连串流动字节/字符,按照先进先出的方式发送的信息的通道中. 数据源:流入通道中的数据的来源 目的地:流出通道的数据的目的地   输入流和输出流 数据源的数 ...

  7. 待续:s5p6818移植 uboot 2014.07 移植

    前言: 之前半年一直在嵌入式Linux移植中挣扎,不知道该从哪个方面开始入手,也失败了很多次,苦思了很久最终决定先从uboot开始. uboot版本的不同会导致添加板子的时候的配置方法会不一样.由于手 ...

  8. MySQL 子查询(四)子查询的优化、将子查询重写为连接

    MySQL 5.7 ref ——13.2.10.10优化子查询 十.子查询的优化 开发正在进行中,因此从长远来看,没有什么优化建议是可靠的.以下列表提供了一些您可能想要使用的有趣技巧.See also ...

  9. (一)easyUI之树形网络

    树形网格(TreeGrid)可以展示有限空间上带有多列和复杂数据电子表 一.案例一:按tree的数据结构来生成 前台 <%@ page language="java" con ...

  10. linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现

    linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现?快速清理木马流程.假设木马的名字是xysbqaxjqy,如果top看不到,可以在/etc/init.d目 ...