MVC 如何分页,还有点击下一页的时候能传递查询FORM里的参数
解决方案 »
- 怎么在客户端判断上传文件大小
- 在Web service 中,怎么读取其程序文件的位置
- 页面使用的用户控件中汉字乱码
- 几个小问题,大家帮忙看看,希望能详细一点,最好能给个小例子
- 动态创建二级域名????
- 说说这三者的区别?
- 谁有asp.net错误处理基类设计的源码提供参考!!!急!!急!!急!!
- 菜鸟问题:布尔值问题
- 我的程序是要实现点击DataGrid中的一行,然后弹出子窗口进行编辑,操作完后刷新父窗口的DataGrid,为什么会出现以下提示呢:"不重新发送信息,
- 推荐学习ASP.NET好一点的书籍(最好重点讲述了GridView空间的)
- 有关下拉树菜单JS样式
- 我的asp.net后台为什么死活获取不到值 代码如下
/// 分页Pager显示
/// </summary>
/// <param name="html"></param>
/// <param name="currentPageStr">标识当前页码的QueryStringKey</param>
/// <param name="pageSize">每页显示</param>
/// <param name="totalCount">总数据量</param>
/// <returns></returns>
public static MvcHtmlString Pager(this HtmlHelper html, int pageSize, int totalCount)
{
int currentPage;
int.TryParse(HttpContext.Current.Request.Form["currentPageIndex"], out currentPage); //与相应的QueryString绑定
if (currentPage == 0)
if (CurrentP != "" && CurrentP != null)
currentPage = int.Parse(CurrentP);
else
currentPage = 1;
var totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //总页数
var output = new StringBuilder();
output.AppendLine("<input type=\"hidden\" id=\"currentPageIndex\" name=\"currentPageIndex\" value=\"" + (HttpContext.Current.Request.Form["currentPageIndex"] == null ? currentPage.ToString() : HttpContext.Current.Request.Form["currentPageIndex"]) + "\"/>"); if (totalPages > 1)
{
if (currentPage != 1)
{//处理首页连接
output.AppendFormat("{0} ", html.RouteLink("首页", new { }, new { onclick = "return Goto(" + 1 + ")" }));
}
if (currentPage > 1)
{//处理上一页的连接
output.Append(html.RouteLink("上一页", new { }, new { onclick = "return Prev_Goto(" + (currentPage - 1) + ")" }));
}
else
{
output.Append("上一页");
}
output.Append(" ");
int currint = 5;
for (int i = 0; i <= 10; i++)
{//一共最多显示10个页码,前面5个,后面5个
if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
if (currint == i)
{//当前页处理
output.Append(string.Format("[{0}]", currentPage));
}
else
{//一般页处理
output.Append(html.RouteLink((currentPage + i - currint).ToString(), new { }, new { onclick = "return Goto(" + (currentPage + i - currint) + ")" }));
}
output.Append(" ");
}
if (currentPage < totalPages)
{//处理下一页的链接
output.Append(html.RouteLink("下一页", new { }, new { onclick = "return Next_Goto(" + (currentPage + 1) + ")" }));
}
else
{
output.Append("下一页");
}
output.Append(" ");
if (currentPage != totalPages)
{
output.Append(html.RouteLink("末页", new { }, new { onclick = "return Goto(" + totalPages + ")" }));
}
output.Append(" ");
}
output.AppendFormat("{0} / {1}", currentPage, totalPages);//这个统计加不加都行 output.AppendLine("");
output.AppendLine("<script type=\"text/javascript\">");
output.AppendLine("function Goto(p) {");
output.AppendLine("$(\"#currentPageIndex\").val(p);");
output.AppendLine("$(\"form\").attr(\"action\", \"Index?p=\" + p);");
output.AppendLine("$(\"form\").submit();");
output.AppendLine("return false;");
output.AppendLine("}");
output.AppendLine("function Prev_Goto(p) {");
output.AppendLine("$(\"#currentPageIndex\").val(parseInt($(\"#currentPageIndex\").val()) - 1);");
output.AppendLine("$(\"form\").attr(\"action\", \"Index?p=\" + p);");
output.AppendLine("$(\"form\").submit();");
output.AppendLine("return false;");
output.AppendLine("}");
output.AppendLine("function Next_Goto(p) {");
output.AppendLine("$(\"#currentPageIndex\").val(parseInt($(\"#currentPageIndex\").val()) + 1);");
output.AppendLine("$(\"form\").attr(\"action\", \"Index?p=\" + p);");
output.AppendLine("$(\"form\").submit();");
output.AppendLine("return false;");
output.AppendLine("}");
output.AppendLine("</script>"); return new MvcHtmlString(output.ToString());
}
public static string CurrentP
{
get
{
return HttpContext.Current.Session["currentPage"] == null ? "" : HttpContext.Current.Session["currentPage"].ToString();
}
}