C# 将 OrderDate 与变量进行比较

标签 c# asp.net-mvc entity-framework code-first

我有一个变量,它在一天、一周和一个月之间有所不同。表单接受它并将其发送回 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/

相关文章:

asp.net-mvc - ASP.NET MVC : Generating multi level menu using recursive helpers

entity-framework - 如何在 Entity Framework 中使用事务?

c# - 我什么时候应该使用 CompiledQuery?

c# - 帮助使用 NHibernate 映射类对象列表

c# - 基类中定义的静态对象对于子类应该是不同的

c# - 是否有一种已知的算法可以找到每对之间距离相同的节点之间的最短距离?

silverlight - Entity Framework : "The member in the conceptual model is not present in the OSpace"

c# - 直接从 C# 中作为不同类方法中的参数传递的成员方法之一检索类实例的引用

Javascript 连接表格单元格 ASP.NET MVC

asp.net-mvc - Knockout js - 脏标志问题