【发布时间】:2010-01-18 22:36:34
【问题描述】:
我目前正在使用 ASP.NET、jQuery 和 JSON 实现客户端分页解决方案。
一直在关注encosia的优秀文章:http://encosia.com/2008/08/20/easily-build-powerful-client-side-ajax-paging-using-jquery/
在我的 Web 方法中,我以 DataTable 的形式从数据库中检索数据:
DataTable categoryProducts = ProductViewerAccess.GetCategoryProducts
("AA", 4, 0, Page.ToString(), out howManyPages, "FALSE", 0, "CostPrice", "asc", destinationList);
然后我将 DataTable 中的数据检索为匿名类型:
var feeds =
from feed in categoryProducts.AsEnumerable()
select new
{
Description = feed.Field<string>("description"),
MfPartNo = feed.Field<string>("MfPN"),
Inventory = feed.Field<Int32>("Inventory")
};
然后匿名类型从 Web 方法返回到客户端:
return feeds.Take(PageSize);
然后模板提取并显示字段:
<tbody>
{#foreach $T.d as post}
<tr>
<td>
{$T.post.Description}
<p>Mfr#: {$T.post.MfPartNo}</p>
</td>
<td>{$T.post.Inventory}</td>
</tr>
{#/for}
</tbody>
这一切都很好。
但是,我想扩展代码以执行一些评估检查(例如,检查 DataTable 中的各个列是否不为 NULL)和其他预处理(例如,调用各种函数以基于图像 ID - 这是代码片段中未显示的 DataTable 中的另一列),然后我将 DataTable 的结果行作为匿名类型返回给客户端。
基本上,我想遍历 DataTable,执行评估检查和预处理,同时手动构建我的匿名类型。或者也许有更好的方法来实现这一点?
有没有我可以做到这一点?
亲切的问候
沃尔特
【问题讨论】:
标签: c# asp.net anonymous-types