Reputation: 6362
How can i iterate the following list and print its values?
public class DummyVersions
{
public List<string> Version { get; set; }
}
[WebMethod]
public static DummyVersions GetDummyVersions()
{
DummyVersions dummyversions = new DummyVersions
{
Version = new List<string>
{
"1.1.0",
"1.1.1",
"1.1.2",
"1.1.3",
"1.1.4",
"1.1.5",
}
};
return dummyversions;
}
$.ajax({
type: "POST",
url: "ManagerBaseKit.aspx/GetDummyVersions",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$.each(result, function (i, val) {
alert(); // ??? here i want to print all version one by one
});
}
});
Upvotes: 0
Views: 118
Reputation: 4817
With the WebMethod
your resonse is automatically converted to json by ASP.NET, so you can iterate through your versions using the code below:
$.each(result.d.Version, function (i, val) {
alert(val);
});
It can be result.d.Version
or result.Version
depending on your ASP.NET version more info about that can be found here: A breaking change between versions of ASP.NET AJAX
Upvotes: 2