title: Display a list in a partial view at post
body: <p>I have this code in my controller:</p>
  
  <pre><code>        [HttpPost]
      public ActionResult Index(double userLat, double userLng)
      {
          var context = new weddingspreeEntities();
          var coordinates = context.Venues
              .Select(loc =&gt; new { vname = loc.VenueName, lat = loc.VenueLat, lng = loc.VenueLong })
              .ToList();
  
                      string venueName = string.Empty;
          List&lt;SearchModel.DistLocation&gt; venDistList = new List&lt;SearchModel.DistLocation&gt;();
  
          for (int i = 0; i &lt; coordinates.Count; i++)
          {
              string name = coordinates[i].vname;
              double? lat = coordinates[i].lat;
              double? lng = coordinates[i].lng;
  
  
  
  
  
              var loc1Lat = lat.Value;
              var loc1Lng = lng.Value;
              var loc2Lat = userLat;
              var loc2Lng = userLng;
  
  
  
  
              double distance = TrackingHelper.CalculateDistance(
                  new SearchModel.Location() { Latitude = loc1Lat, Longitude = loc1Lng },
                  new SearchModel.Location() { Latitude = loc2Lat, Longitude = loc2Lng });
  
              //convert kilometers to miles
              double distMiles = distance * 0.621371192;
  
              venueName = name;
  
  
  
  
              venDistList.Add(new SearchModel.DistLocation() { venName = name, Distance = distMiles });
          }
  
  
  
  
          return View(venDistList);
      }
  </code></pre>
  
  <p>I have this code in my view:</p>
  
  <pre><code>    &lt;div class="row"&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-6"&gt;
              @using (Html.BeginForm("Search", "Home", FormMethod.Post))
              {
                  @*@Html.TextBoxFor(model =&gt; model.cityName)*@
                  &lt;label&gt;Enter City and State or Zip Code&lt;/label&gt;
                  &lt;input type="text" id="citystate" name="citystate" /&gt;
                  &lt;label&gt;Enter Your Wedding Date&lt;/label&gt;
                  &lt;input class="datefield" data-val="true" data-val-required="Date is required" id="weddingDate" name="weddingDate" type="date" value="1/11/1989" /&gt;
                  &lt;label&gt;Enter Your Guest Count&lt;/label&gt;
                  &lt;input type="text" id="guestcount" name="guestcount" /&gt;
                  &lt;input type="button" id="search" name="search" value="Search for Venues" /&gt;
              }
          &lt;/div&gt;
  
          &lt;!--This is the div where the google map will render --&gt;
          &lt;div class="col-md-6"&gt;
              &lt;div id="map_canvas" style="height: 600px;"&gt;&lt;/div&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;  
  
  &lt;/div&gt;
  
      &lt;div&gt;
          @Html.Partial("_SearchResults")
      &lt;/div&gt;
  </code></pre>
  
  <p>I have omitted some of my view for brevity</p>
  
  <p>This is the partial view I am trying to render:</p>
  
  <pre><code>    @model IEnumerable&lt;WeddingSpree_Alpha.Models.SearchModel.DistLocation&gt;
  
  @{ 
      Layout = null;
  }
  @using (Html.BeginForm("Index", "Home", FormMethod.Post))
  {
      foreach (var item in Model)
      {
          @item.venName
          @item.Distance
      }
  }
  </code></pre>
  
  <p>What I am trying to do is to have the user enter the values in the search box and then after the click post the results (in the list named venDistList) to the view using a foreach statement.</p>
  
  <p>The model looks like this:</p>
  
  <pre><code>    public class SearchModel
  {
      public string cityName { get; set; }
      public DateTime weddingDate { get; set; }
      public int guestCount { get; set; }
  
  
      public class Location
      {
          public double Latitude { get; set; }
          public double Longitude { get; set; }
      }
  
      public class DistLocation
      {
          public string venName { get; set; }
          public double Distance { get; set; }
      }
  }
  </code></pre>
  
  <p>I would like the list results to populate after the button click (post) on the page.  I thought my code would do that however.  I get the following error: </p>
  
  <blockquote>
    <p>System.NullReferenceException: 'Object reference not set to an instance of an object'</p>
  </blockquote>
  
  <p>I know that error happens when you try to use a model that is not populated yet but I thought I did that in my controller code?  What exactly could be throwing that error?</p>
  
  <p>This is the controller code for my partial view:</p>
  
  <pre><code>        public ActionResult _SearchResults(SearchModel model)
      {
          return View();
      }
  </code></pre>