Is this even possible with jquery? My javascript code works in terms of returning data with the get statement, and after debugging I verified that the uploadCategories did indeed contain the requested objects, but for whatever reason they are not being rendered to the select tag. What am I missing here?
Javascript:
var uploadController = function($scope) {
// upload category array
$scope.uploadCategories = [];
$scope.category = "";
// get categories
$.get('/api/Upload/UploadCategories', function(data) {
// update array
$scope.uploadCategories = [];
$.each(data, function(i, item) {
$scope.uploadCategories.push({
Id: item.Id,
Category: item.Category
});
// set active category
$scope.category = $scope.uploadCategories[0].Category;
});
}, "json");
};
HTML:
<form class="text-center" action="/Upload/AdminUpload" method="post"
data-ng-controller="uploadController">
<fieldset class="form-group" style="display: inline-block;">
<legend>File Info</legend>
<!--Upload Category-->
<div class="form-group">
<label for="catId">Category</label>
<select id="catId" ng-model="category"
ng-options="c.Category for c in uploadCategories"></select>
</div>
<button type="submit" formenctype="multipart/form-data">Upload</button>
</fieldset>
$scope.apply(function(){});is the way to go.