积极答复者
asp.net mvc分页

问题
答案
-
linq 分 linq to sql 、linq to entity 所以 当使用 mvc +ado.net时 可以使用 Linq to entity 照样可以使用啊 你需要源代码吗
public static void PagedList<T>(this HtmlHelper helper,
int listSize,
IEnumerable<T> data,
ShowItemHandler<T> callback,
ShowPageHandler pageCallback,
ShowEmptyHandler emptyCallback)
{
if (data == null || data.Count() == 0)
{
if (emptyCallback != null) emptyCallback();
return;
}string p1 = helper.ViewContext.HttpContext.Request.QueryString["p"];
int p = 0;
if (!string.IsNullOrWhiteSpace(p1))
{
if (!int.TryParse(p1, out p))
p = 0;
if (p < 0) p = 0;
}
int c = data.Count();
if (p * listSize >= c) p = 0;if (callback != null)
foreach (T item in data.Skip(p * listSize).Take(listSize))
callback(item);if (pageCallback != null)
{
if ((p + 1) * listSize < c)
pageCallback(Resources.Strings.下一页, p + 1);
if (p > 0)
pageCallback(Resources.Strings.上一页, p - 1);
}
}
}- 已标记为答案 asp.net mvc小菜鸟 2010年8月5日 6:56
全部回复
-
linq 分 linq to sql 、linq to entity 所以 当使用 mvc +ado.net时 可以使用 Linq to entity 照样可以使用啊 你需要源代码吗
public static void PagedList<T>(this HtmlHelper helper,
int listSize,
IEnumerable<T> data,
ShowItemHandler<T> callback,
ShowPageHandler pageCallback,
ShowEmptyHandler emptyCallback)
{
if (data == null || data.Count() == 0)
{
if (emptyCallback != null) emptyCallback();
return;
}string p1 = helper.ViewContext.HttpContext.Request.QueryString["p"];
int p = 0;
if (!string.IsNullOrWhiteSpace(p1))
{
if (!int.TryParse(p1, out p))
p = 0;
if (p < 0) p = 0;
}
int c = data.Count();
if (p * listSize >= c) p = 0;if (callback != null)
foreach (T item in data.Skip(p * listSize).Take(listSize))
callback(item);if (pageCallback != null)
{
if ((p + 1) * listSize < c)
pageCallback(Resources.Strings.下一页, p + 1);
if (p > 0)
pageCallback(Resources.Strings.上一页, p - 1);
}
}
}- 已标记为答案 asp.net mvc小菜鸟 2010年8月5日 6:56