我正在根据日期范围搜索数据库中的数据。
在搜索框中,我如何才能从数据选择器中选择数据。
这是我的代码:
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>
先感谢您