【问题标题】:Multiple search in list列表中的多个搜索
【发布时间】:2019-10-17 13:17:45
【问题描述】:

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

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" />

}

【问题讨论】:

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


    【解决方案1】:

    根据您问题中的详细信息量很难判断您在寻找什么,但您可以尝试下面的代码。

        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);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多