Linq 用于筛选具有日期范围的数据的数据选择器
我正在根据日期范围搜索数据库中的数据 在搜索框中,如何从数据采集器中提取数据 这是我的密码:Linq 用于筛选具有日期范围的数据的数据选择器,linq,asp.net-mvc-4,filter,datapicker,Linq,Asp.net Mvc 4,Filter,Datapicker,我正在根据日期范围搜索数据库中的数据 在搜索框中,如何从数据采集器中提取数据 这是我的密码: public ActionResult List(DateTime startDate, DateTime endDate) { //var cards = new List<Card>(); //using (CardDBEntities _db = new CardDBEntities() ) //{ //
public ActionResult List(DateTime startDate, DateTime endDate)
{
//var cards = new List<Card>();
//using (CardDBEntities _db = new CardDBEntities() )
//{
// cards = _db.Cards.ToList();
//}
using (var db = new CardDBEntities())
{
var cards = (from c in db.Cards
join d in db.RegistrationDTs
on c.CardId equals d.CardId
where d.RegistrationDateTime >= startDate &&
d.RegistrationDateTime <= endDate
select new Model
{
CardId = d.CardId,
Description = c.Description,
RegistrationDateTime = d.RegistrationDateTime
}).OrderByDescending(x => x.RegistrationDateTime)
.ToList();
ViewData["cards"] = cards;
return View();
我的看法是:
@using(Html.BeginForm())
{
<fieldset>
<legend>Search criteria</legend>
@Html.Label("startDate", "Start Date:")
@Html.TextBox("startDate", null, new { @class = "DateTime" })
@Html.Label("endDate", "End Date:")
@Html.TextBox("endDate", null, new { @class = "DateTime" })
<input type="submit" value="Apply" />
</fieldset>
提前感谢您您可以使用
工作区:
只需浏览一下,您会发现更多选项。您有任何错误吗?顺便问一下,是DatePicker吗?或者数据采集器您可以使用JqueryUI数据采集器,它的使用非常简单。。我没有获取日期选择器:/I您必须在引用jQuery日期选择器之前添加jQuery,jsI现在将检查它。非常感谢。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>
</head>
<body>
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
</body>
</html>