我有一个变量,它在一天,一周和一个月之间有所不同。表单采用此方法并将其发送回控制器。但是我想在1周内查看"查看订单"使用下面的方法工作。没有错误,它根本没有显示任何订单。
Controller; (Just trying to get it to work before i change the amount of days)
else if (date == "day")
{
DateTime today = DateTime.Now;
DateTime answer = today.AddDays(10);
return View(db.Orders.Where(x => x.OrderDate <= answer).ToList());
}
这是我的观点,包括我使用的其他部分;
@using (Html.BeginForm("Index", "EditOrders", FormMethod.Get))
{
//the following are search options
<b> Search for: </b>@Html.RadioButton("option", "FirstName") <text>First Name</text> @Html.RadioButton("option", "PostalCode") <text> Post-Code </text>
@Html.RadioButton("option", "Username")<text>Email-Address</text> @Html.TextBox("search")
<text>Orders Made </text><select id="date" name="date">
<option value="none">No day</option>
<option value="day">In the last day</option>
<option value="week">In the last week</option>
<option value="month">In the last month</option>
<option value="year">In the last year</option>
</select>
<input type="submit" name="submit" value="Search" />
}
答案 0 :(得分:0)
我的代码是正确的,现在可以使用了,我所要做的就是添加一个 - 添加天来查看过去
DateTime today = DateTime.Now;
DateTime answer = today.AddDays(-10);