title: MVC C# Select Where
body: <p>I am trying to add filter by ID for the following: </p>
  
  <pre><code>public ActionResult Index()
  {
      var model = from o in new MainDBContext().OffLinePayments
                  select new EditOffLinePayment 
                  {
                      ID = o.ID,
                      Amount = o.Amount 
                  };
      return View(model);
  }
  </code></pre>
  
  <p>What I would like to do is the following:</p>
  
  <pre><code>public ActionResult Index(long? id)
  {
      if (id != null)
      {
          var model = from o in new MainDBContext().OffLinePayments
                      **Where Assigned_ID == id**
                      select new EditOffLinePayment 
                      {
                          ID = o.ID,
                          Amount = o.Amount 
                      };
          return View(model);
      }
      else 
      {       
          var model = from o in new MainDBContext().OffLinePayments
                      select new EditOffLinePayment 
                      {
                          ID = o.ID,
                          Amount = o.Amount 
                      };
          return View(model);
      }
  }
  </code></pre>