I'm trying to populate a DropDown from a Json result using jQuery.
I have the following class:
class MyOption
{
int Id { get; set; }
string Name { get; set; }
}
I'm not sure how to get a list of these into my Json result. At the moment I have the following, I'm not sure if it's correct but it compiles and runs:
return Json(new
{
user = userInfo.DisplayName,
timestamp = DateTime.Now,
options = GetValidOptions() // returns List<MyOption>
});
And now in jQuery I'm trying to get the options with things like:
function myFunc(data) {
var obj = data.get_response().get_object();
$.each(obj.options, function(option) {
alert(option.Id + option.Name); // doesn't work
});
}
What do I need to do to get this working?