2 qwer 123789 qwer_123789 于 2014.12.12 18:41 提问

求解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
devmiao   Ds   Rxr 2014.12.13 01: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.......

qwer_123789
qwer_123789   2014.12.12 18:42

求大神啊。真心不会做啊

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!