asp.net mvc怎么按时间段查询 下面这段代码是查询代码 如何在C层和V层实现
///动态搜索类new///{?intUserID=0用户ID///?DateTimeBeginDate=DateTime.Now开始时间///?DateTimeEndD...
/// 动态搜索类new
/// {?int UserID=0 用户ID
/// ?DateTime BeginDate=DateTime.Now 开始时间
/// ?DateTime EndDate=DateTime.Now 结束时间
/// ?int AccountID=0 账号类型
/// ?string OrderFeild="Order Desc" 排序字段和方式
/// }
/// </param>
/// <param name="iPageIndex">页码</param>
/// <param name="iPageSize">每页显示条数</param>
/// <returns></returns>
public PagedList<Finance_WithdrawalDetail> GetWithdrawalDetail(dynamic dySearch, int iPageIndex, int iPageSize)
{
try
{
var queryBuilder = QueryBuilder.Create<Finance_WithdrawalDetail>();
ExpandoObject doSearch = dySearch;
var Keys = ((IDictionary<String, Object>)doSearch).Keys;
if (Keys.Contains("UserID")) //用户ID
{
queryBuilder.Equals(n => n.UserID, (int)dySearch.UserID);
}
if (Keys.Contains("BeginDate")) //开始时间
{
queryBuilder.Between(n => n.AddTime, (DateTime)dySearch.BeginDate, DateTime.MaxValue);
}
if (Keys.Contains("EndDate")) //结束时间
{
queryBuilder.Between(n => n.AddTime, DateTime.MinValue, (DateTime)dySearch.EndDate);
}
string strOrder = string.Empty;
if (Keys.Contains("OrderFeild") && !string.IsNullOrEmpty(dySearch.OrderFeild)) //排序字段和方式
{
strOrder = dySearch.OrderFeild;
}
else
{
strOrder = "ID Desc";
}
var list = db.Finance_WithdrawalDetail.Where(queryBuilder.Expression).myorder(strOrder);
return new PagedList<Finance_WithdrawalDetail>(list, iPageIndex, iPageSize);
}
catch (Exception ex)
{
return null;
}
} 展开
/// {?int UserID=0 用户ID
/// ?DateTime BeginDate=DateTime.Now 开始时间
/// ?DateTime EndDate=DateTime.Now 结束时间
/// ?int AccountID=0 账号类型
/// ?string OrderFeild="Order Desc" 排序字段和方式
/// }
/// </param>
/// <param name="iPageIndex">页码</param>
/// <param name="iPageSize">每页显示条数</param>
/// <returns></returns>
public PagedList<Finance_WithdrawalDetail> GetWithdrawalDetail(dynamic dySearch, int iPageIndex, int iPageSize)
{
try
{
var queryBuilder = QueryBuilder.Create<Finance_WithdrawalDetail>();
ExpandoObject doSearch = dySearch;
var Keys = ((IDictionary<String, Object>)doSearch).Keys;
if (Keys.Contains("UserID")) //用户ID
{
queryBuilder.Equals(n => n.UserID, (int)dySearch.UserID);
}
if (Keys.Contains("BeginDate")) //开始时间
{
queryBuilder.Between(n => n.AddTime, (DateTime)dySearch.BeginDate, DateTime.MaxValue);
}
if (Keys.Contains("EndDate")) //结束时间
{
queryBuilder.Between(n => n.AddTime, DateTime.MinValue, (DateTime)dySearch.EndDate);
}
string strOrder = string.Empty;
if (Keys.Contains("OrderFeild") && !string.IsNullOrEmpty(dySearch.OrderFeild)) //排序字段和方式
{
strOrder = dySearch.OrderFeild;
}
else
{
strOrder = "ID Desc";
}
var list = db.Finance_WithdrawalDetail.Where(queryBuilder.Expression).myorder(strOrder);
return new PagedList<Finance_WithdrawalDetail>(list, iPageIndex, iPageSize);
}
catch (Exception ex)
{
return null;
}
} 展开
展开全部
c 层 调用
viewdata["data"]= PagedList<Finance_WithdrawalDetail> GetWithdrawalDetail(....);
return view();
v层
@{var data = viewdata["data"] as PagedList<Finance_WithdrawalDetail>;
<table>
@ foreach(var d in data)
{
........<td>@d.......</td>
}
</table>
}
viewdata["data"]= PagedList<Finance_WithdrawalDetail> GetWithdrawalDetail(....);
return view();
v层
@{var data = viewdata["data"] as PagedList<Finance_WithdrawalDetail>;
<table>
@ foreach(var d in data)
{
........<td>@d.......</td>
}
</table>
}
追问
在V层不是直接显示出来的 是要求输入时间段 点击查询按钮查询
追答
1、做一个 form ,加入时间选择框 提交到c c 层里面接受到参数后 根据参数去过滤记录
然后输出的记录就是过滤的了
2、全部json ajax把记录请求到前台,数据不多的情况下,点击查询的时候 只在客户端过滤 ,利用js操作 也行
3、建议用ext 等js 框架来实现gird的展示 ,他的例子中也有一些教程来展示如何请求数据,也有过滤方面的东西
4、asp.net mvc 我最为推荐的 是你使用 telerik ,可以搜索下 ,看下这个开源的扩展框架,可能使你的开发起来更容易 ,可以看下他的例子和源码,分页 查询什么的都是小问题了,目前asp.net mvc这块可能只有它这块支持好点
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询