I have controller
var subCategories = m_listsRepository.GetSubCategories(id);
var items = subCategories.Select(x=>new MyDataNameAndId(){Id = x.Value, Name = x.Text});
return Json(items);
And ajax:
$.ajax({
url: urlString,
type: 'POST',
data: JSON.stringify({ id: districtId }),
dataType: 'json',
contentType: 'application/json',
cache: 'false',
success: function (data) {
alert("success");
$.each(data, function (key, MyDataNameAndId) {
alert(key);//== 0
alert(MyDataNameAndId);// then throws
$('select#ChangeOnsubCategoryId').append('<option value="0">Select One</option>');
$.each(MyDataNameAndId, function (index, manager) {
$('select#ChangeOnsubCategoryId').append(
'<option value="' + manager.Id + '">'
+ manager.Name +
'</option>');
});
});
}
});
what am I doing wrong?
UPDATE:
Controller is worked.
alert("success"); - is show
alert(key); - is show 0
alert(MyDataNameAndId); - not show.
I need generate in 'select#ChangeOnsubCategoryId' options from select#ChangeOnsubCategoryId
How do this? this understand?
I do not know how to show what passed json
json string:
[{"Id":"53","Name":"??????"}]
No comments:
Post a Comment