I am trying to create an input with the id and value attributes set from a JSON. I have an ajax call which gets the JSON and the data returned is just fine, and for each object from the JSON I want to create a button with an ID and a value from the JSON.
The Ajax call:
$.ajax({
type: "GET",
url: '@Url.Action("GetSubjects", "CommAPI")',
dataType: "json",
success: function (data) {
$.each(data, function (index, element) {
$('#subjects').append('<input type ="button" id=" ' + element.Id + ' " value=' + element.Title + ' class=k-button />');
});
},
});
The objects from the JSON however have 5 additional properties in them, not just Id and Title. When placing the debugger at the line with the input creation, the Id and Title are undefined.
How may I create these inputs from this JSON?
Returned JSON copied from the Console:
14:41:57.928 {"Data":[{"Id":1,"IdCSite":1,"IdDEvent":1,"Title":"Test","CaseName":null,"Description":"dsadasdasda","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false},{"Id":2,"IdCSite":1,"IdDEvent":1,"Title":"Test2","CaseName":null,"Description":"sdadasdas","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false},{"Id":3,"IdCSite":1,"IdDEvent":1,"Title":"test 3","CaseName":null,"Description":"sdadasdasda","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false}],"Total":3,"AggregateResults":null,"Errors":null}1 messageboard:128:25
$.each(data.Data,update to this and it does not have any key namedId