程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> mvc-求解MVC中根據時間段來查詢

mvc-求解MVC中根據時間段來查詢

編輯:編程綜合問答
求解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">
                

        

最佳回答:


/// 動態搜索類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. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved