title: Populating a dropdownlist with AngularJS
body: <p>I want to populate a dropdownlist with values from a table I created called Venues. This table has only two things in it, the Venue Id and Name.</p>
  
  <p>I created a Code First Entity Data Model from the database that holds the table Venues and I created this method in my controller:</p>
  
  <pre><code>public JsonResult GetVenues()
      {
          using (ReservationsModel dc = new ReservationsModel())
          {
              var v = dc.Venues.OrderBy(a =&gt; a.Name).ToList();
              return new JsonResult { Data = v, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
          }
  </code></pre>
  
  <p>then in my script i added:</p>
  
  <pre><code>$scope.selectedVenue = null;
  $scope.venues = [];
  $http.get("/home/getvenues").success(function (data) {
      angular.forEach(data, function (item) {
          venues.push(item.Name);
      });
      $scope.list = venues;
  }).error(function (status) {
      alert(status);
  });
  
  $scope.selectedVenue = $scope.venues[i].Name;
  </code></pre>
  
  <p>and in my view I have:</p>
  
  <pre><code>&lt;select ng-model="selectedVenue" ng-options="item in venues"&gt;
      &lt;option value=""&gt;-- Select Venue --&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I came from these guides:</p>
  
  <p><a href="http://www.dotnetawesome.com/2016/04/implement-event-scheduler-calendar-angularjs.html" rel="nofollow noreferrer">http://www.dotnetawesome.com/2016/04/implement-event-scheduler-calendar-angularjs.html</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15688313/how-can-i-populate-a-select-dropdown-list-from-a-json-feed-with-angularjs">How can I populate a select dropdown list from a JSON feed with AngularJS?</a></p>
  
  <p><a href="https://jsfiddle.net/pravinmagar/Ljgk8oy0/" rel="nofollow noreferrer">https://jsfiddle.net/pravinmagar/Ljgk8oy0/</a></p>