一个根据时间段来查询所需信息的代码。
控制器代码:
public ActionResult SelectOperation(BsgridPage bsgridPage, string time1, string time2)
{
var list = (from tbOperator in myModel.SYS_Operator
orderby tbOperator.OperatorID descending
select new Operation
{
OperatorID = tbOperator.OperatorID,
OperationTime = tbOperator.OperationTime,
OperationMatter = tbOperator.OperationMatter,
Operator = tbOperator.Operator,
Matter = tbOperator.Matter,
ReleaseTimeStr = tbOperator.OperationTime.ToString()
}
).ToList();
if (!string.IsNullOrEmpty(time1) && !string.IsNullOrEmpty(time2))
{
DateTime dbtime1 = Convert.ToDateTime(time1);
DateTime dbtime2 = Convert.ToDateTime(time2);
list = list.Where(m => m.OperationTime >= dbtime1 && m.OperationTime <= dbtime2).ToList();
}
int totals = list.Count();//数据的总条数
List<Operation> listDealInforAll = list
.Skip(bsgridPage.GetStartIndex())
.Take(bsgridPage.pageSize).ToList();
Bsgrid<Operation> bsgrid = new Bsgrid<Operation>();
bsgrid.success = true;//返回的状态
bsgrid.totalRows = totals;//总条数
bsgrid.curPage = bsgridPage.curPage;//当前的页数
bsgrid.data = listDealInforAll;//返回的分页的成绩信息
return Json(bsgrid, JsonRequestBehavior.AllowGet);
}
HTML代码:
function Select() {
var time1 = $("#time1").val();
var time2 = $("#time2").val();
if (time1 == null || time1 == undefined) {
time1 = "";
}
if (time2 == null || time2 == undefined) {
time2 ="";
}
tbApprove.search({ time1: time1, time2: time2 });
}