title: How To Search Date Range ASP.NET MVC?
body: <p>How do I search date range using the controller? So far I am not able to solve it with the code that I used below. The search for Trip name &amp; country is working.
  (P.s I am new to this programming language...) Thank you in advance.</p>
  
  <h2>Controller</h2>
  
  <pre><code>public ActionResult Index(string search, DateTime? startdate, DateTime?  enddate)
      {
          if (Session["StaffName"] != null)
          {
              //original
              DateTime str = DateTime.UtcNow;
              ViewBag.Datetime = str;
              ViewBag.startdate = startdate;
              ViewBag.enddate = enddate;
              var Trips = from x in db.Trips
                          select x;
              if (search != null)
              {
                  return View(Trips.Where(x =&gt; x.TripName.Contains(search) || x.Country.Contains(search)  || search == null).ToList());
              }
              if (startdate != null &amp;&amp; enddate != null)
              {
                  return View(Trips.Where(x =&gt;  startdate &gt; x.startDate &amp;&amp; x.endDate &lt; enddate ).ToList());
              }
              return View(Trips.ToList());
          }
      }
  </code></pre>