Tutorial :Using Json and jQuery to populate DropDown from a list of custom classes in Asp.Net MVC 2



Question:

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?


Solution:1

You have an example here


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »