This can run well with MSSQL,but after i change the database with mysql,it just show the firt
page, the viewdata.model can't get the next page record.
code in controllor:
index action:
if (Request["page"] != null)
{
ViewData["page"] = SqlHelper.Pager(Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?")), Convert.ToInt32(Request["page"]), n.Count(), 5, 3);
n = n.Skip((Convert.ToInt32(Request["page"]) - 1) * 5).Take(5);
}
else
{
ViewData["page"] = SqlHelper.Pager(Request.RawUrl, 1, n.Count(), 5, 3);
n = n.Skip(0).Take(5);
}
return View(n);
code in SqlHelper:
public static string Pager(string url1, int id, int count, int size, int show)
{
string pager = "";
string url = url1.Contains("?") ? url1 + "&page=" : url1 + "?page=";
pager = "<a href=\"" + url + (1) + "\"><<</a>";
if (id != 1)
{
pager += "<a href=\"" + url + (id - 1) + "\"><</a>";
}
if (id > (show + 1))
{
pager += "<a href=\"" + url + (id - show - 1) + "\">..</a>";
}
int page_count = count / size;
if (page_count == 0)
{
return "";
}
for (int i = id - show; i <= id + show; i++)
{
if (id == i)
pager += "<span>" + i + "</span>";
else if (i > 0 && i <= page_count)
pager += "<a href=\"" + url + i + "\">" + i + "</a>";
}
if (id < page_count - show)
{
pager += "<a href=\"" + url + (id + show + 1) + "\">..</a>";
}
if (id != page_count)
{
pager += "<a href=\"" + url + (id + 1) + "\">></a>";
}
pager += "<a href=\"" + url + page_count + "\">" + page_count + "</a>";
return pager;
}
public static string pagination(int total, int per, int page, string query_string)
{
int allpage = 0;
int next = 0;
int pre = 0;
int startcount = 0;
int endcount = 0;
string pagestr = "";
if (page < 1) { page = 1; }
//计算总页数
if (per != 0)
{
allpage = (total / per);
allpage = ((total % per) != 0 ? allpage + 1 : allpage);
allpage = (allpage == 0 ? 1 : allpage);
}
next = page + 1;
pre = page - 1;
startcount = (page + 5) > allpage ? allpage - 9 : page - 4;
endcount = page < 5 ? 10 : page + 5;
if (startcount < 1) { startcount = 1; }
if (allpage < endcount) { endcount = allpage;
pagestr = "totally" + allpage + "page ";
pagestr += page > 1 ? "<a href=\"" + query_string + "?page=1\">first page</a> <a href=\"" + query_string + "?page=" + pre + "\">pre page</a>" : "first page next page";
for (int i = startcount; i <= endcount; i++)
{
pagestr += page == i ? " <font color=\"#ff0000\">" + i + "</font>" : " <a href=\"" + query_string + "?page=" + i + "\">" + i + "</a>";
}
pagestr += page != allpage ? " <a href=\"" + query_string + "?page=" + next + "\">next page</a> <a href=\"" + query_string + "?page=" + allpage + "\">last page</a>" : " next page last page";
return pagestr;
}
index.aspx code:
<% foreach (MvcBBS.Model.Article m in (IEnumerable)ViewData.Model)
{ %>
<dt class="d"><%= Html.ActionLink(Html.Encode(m.Title), "Read", "Article", new { ID = m.ID}, null)%>
<% if (Session["Flag"] == "1")
{ %>
<span style="float:right">
<%= Ajax.ActionLink("[Delete]", "Delete", new { ID = m.ID, SortID = m.Sort }, new AjaxOptions { UpdateTargetId = "divArticleList", Confirm="are you sure?" })%></span>
<%} %>
<span style="color:#0099CC"><%= m.ReplyNum %></span> / <%= m.ReadNum %>
<%= m.author%>
<%= m.EntryDate %></dt>
<%} %>
<div class="page"> <%=ViewData["page"] %> </div>
related css:
.pagecomments{
width: 500px;
margin: 27px;
padding: 27px;
}
.pagecomments h3{
color: #6a6a6a;
}
.pagecomments a{
color: #b7a795;
text-decoration: none;
font-size: 11px;
background-color: #fdf8f1;
}
.pagecomments a:hover{
color: #a9b880;
}
.pagecomments ol{
list-style: none;
margin: 10px 0;
padding: 0;
}
.pagecomments ol li{
list-style: none;
margin: 10px 0 0;
padding: 0 0 10px;
border-bottom: 1px dotted #bbb7b0;
line-height: 22px;
}
#pagecomments span.comment-author{
font-weight: bold;
text-decoration: underline;
}
#respond{
padding: 10px;
border: 1px dotted #bbb7b0;
}
someone would help me? thx a lot!!!