title: Best way to handle returning no results when trying to find a model?
body: <p><em>I am trying to teach myself MVC 6 using online sources, but they do not always cover exactly what I am trying to learn. Apologies if I seem ignorant to something that should be fairly obvious.</em></p>
  
  <p>In this case, I am passing data to the view using:</p>
  
  <pre><code>   public ActionResult Index(int? id)
      {
          foreach (Customer c in _cList)
          {
              if (c.Id == id)
              {
                  return View(c);
              }
          }
          return View(new Customer());
      }
  </code></pre>
  
  <p>Is returning the view with an empty model the best way of dealing with a "no matching id" result of a foreach search? </p>
  
  <p>The view then calls the model as such:</p>
  
  <pre><code>@if (Model.Id != 0)
  {
      &lt;P&gt; @Model.Name &lt;/P&gt;
      &lt;P&gt; @Model.Email &lt;/P&gt;
  }
  else
  {
      &lt;P&gt; Nothing found!&lt;/P&gt;
  }
  </code></pre>
  
  <p>While it does infact work, I would like to know if this is the right way to handle this. 
  It just feels a bit... hacky. Creating an empty model just to return with an object that won't cause a null pointer exception?  </p>
  
  <p>While it shouldn't be necessary information- the _cList is declared as <code>private readonly List&lt;Customer&gt; _cList = new List&lt;Customer&gt;()</code> as an inline pseudo database - For those of who who are finding this via google and are curious. It makes foreach work and therefore simplifies the searching. Not idealistic in an actual SQL Query search. A scalar function might be what you will have to use. </p>