Я создаю кнопку, у которой есть событие щелчка, которому для работы нужен идентификатор.
Эта строка создает ошибку:
button.addEventListener("click", e => LikeComment(result[i].id));
Теперь при отладке я могу скажите, что он знает, что result [i] .id равен 1. Итак, очевидно, что он способен его получить.
Обновление:
Это метод javascript
function GetComments(id) {
comment.style.display = 'block';
$.ajax({
url: '/Account/GetComments',
dataType: 'json',
success: function (result) {
for (var i = 0; i < result.length; i++) {
var buttonId = "LikeComment" + result[i].id;
}
},
});
}
Здесь я получаю массив из
public JsonResult GetComments(long postId)
{
var comment1 = new Comment()
{
Id = 1,
};
var comment2 = new Comment()
{
Id = 2,
};
Comment[] comments = { comment1, comment2 };
return Json(comments);
}
}