qwer_123789 2014-12-12 10:41 采纳率: 50%
浏览 2139
已采纳

求解MVC中根据时间段来查询

public ActionResult time(DateTime time1, DateTime time2)
    {
       var time1=



                         //new SqlParameter("@begin",begin.ToString("yyyy-MM-dd 00:00:00")),
                         //new SqlParameter("@end",end.ToString("yyyy-MM-dd 23:59:59")),
        return View();
    }
    public ActionResult Moneydetail(int pageIndex = 1, int pageSize = 15)
    {

        if (!Request.IsAuthenticated)
        {

            return Content("<script>alert('亲,你还没有登录登录!');location='/account/login?returnUrl=" + Request.RawUrl + "';</script>");
        }
        var monerdetail = db.JifenList.Where(p => p.UserID == Wz.Core.WebContext.Current.User.Id && p.Time > time1 && p.Time < time2).ToList();
        return View();
    }


}

后台那个时间方法怎么写

我的帐户明细

    <div class="clearfix">
        <form action="" method="post">
            <input type="hidden" value="ok" name="search">
            <div class="page_info">
                时间:
                <input name="time1" type="text" id="time1" value="time1" class="hasDatepicker">
                至
                <input name="time2" type="text" id="time2" value="time2" class="hasDatepicker">
                <input type="submit" value="搜索" class="btn">
            </div>
                            这是前台
  • 写回答

2条回答 默认 最新

  • devmiao 2014-12-12 17:13
    关注

    /// 动态搜索类new
    /// {?int UserID=0 用户ID
    /// ?DateTime BeginDate=DateTime.Now 开始时间
    /// ?DateTime EndDate=DateTime.Now 结束时间
    /// ?int AccountID=0 账号类型
    /// ?string OrderFeild="Order Desc" 排序字段和方式
    /// }
    ///
    /// 页码
    /// 每页显示条数
    ///
    public PagedList GetWithdrawalDetail(dynamic dySearch, int iPageIndex, int iPageSize)
    {
    try
    {
    var queryBuilder = QueryBuilder.Create();
    ExpandoObject doSearch = dySearch;
    var Keys = ((IDictionary)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 GetWithdrawalDetail(....);
    return view();

    v层

    @{var data = viewdata["data"] as PagedList;

    @ foreach(var d in data) { ........ }
    @d.......

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?