How can you fill a DropDownList using jQuery?
I have a call to my controller :
$.getJSON('@Url.Action("GetCategories")', { groupId: selectedGroup }, function (categories) {
This returns objects from the class Category :
public class Category
{
public int Id { get; set; }
public int GroupId { get; set; }
public string Description { get; set; }
}
How do I get the Id from Category in the DropDownList value and Description from Category in the Text?
This is not working..
$.each(categories, function (index, category) {
categoriesSelect.append($('<option/>', {
value: category.Id,
text: category.Description
}));
});
This is not working, it gives the message "category not defined".
This is what is in category:
