列表中的多个搜索

时间:2019-05-31 23:33:09

标签: asp.net asp.net-mvc entity-framework model-view-controller

我正在尝试搜索具有多个参数的列表,但是我输入的参数返回了一个空列表

public ActionResult Index(string accountNo, string bookingDate, string productType)
        {
            DataModel db = new DataModel();
            var kIRDates = from m in db.KIRDates
                           where m.Verbund.ToString() == accountNo.ToString() || accountNo.ToString() == null || accountNo.ToString() == ""
                           where m.Belegdatum.ToString() == bookingDate.ToString() || bookingDate.ToString() == null || bookingDate.ToString() == ""

                           where m.Sparte == productType || productType == null || productType == ""
                           select m;
            Session["kIRDates"] = kIRDates.ToList<KIRDate>();
            return View(kIRDates);
        }
@using (Html.BeginForm("Index", "KIRData", FormMethod.Get))
{

    @Html.TextBox("accountNo")
    @Html.TextBox("bookingDate")
    @Html.TextBox("productType")
    <input type="submit" value="Search" />

}

1 个答案:

答案 0 :(得分:0)

根据问题的详细程度很难分辨出您要查找的内容,但是您可以尝试以下代码。

    public ActionResult Index(string accountNo, string bookingDate, string productType)
    {
        DataModel db = new DataModel();
        var kIRDates = db.KIRDates.Where(m => m.Verbund.ToString() == accountNo || m.Belegdatum.ToString() == bookingDate || m.Sparte.ToString() == productType);

        Session["kIRDates"] = kIRDates.ToList<KIRDate>();
        return View(kIRDates);
    }