我有一个变量,它在一天、一周和一个月之间有所不同。表单接受它并将其发送回 Controller 。但是,我正在尝试使用下面的方法让“查看 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" />
}
最佳答案
我的代码是正确的并且现在可以工作,我所要做的就是在过去的添加天数中添加一个 -
DateTime today = DateTime.Now;
DateTime answer = today.AddDays(-10);
关于C# 将 OrderDate 与变量进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36886490/