我在Generic Handler中有这个方法,它从查询字符串中获取id并将所有类似的值发送到jquery函数来填充标签
<div class="voteDown">
<asp:LinkButton ID="btnDeslick" runat="server" data-id='<%# Eval("CommentId") %>' CssClass="A1" ClientIDMode="Static">
<i class="fa fa-thumbs-down"></i>
<asp:Label ID="lblDesLike" runat="server" Text='<%# Bind("CommentDesLike") %>' ClientIDMode="Static" CssClass="A2" ></asp:Label>
</asp:LinkButton>
</div>
这是通用处理程序代码
int commentId = Convert.ToInt32(context.Request.QueryString["CommentiD"]);
NewsCommentLikesEntity obj = new NewsCommentLikesEntity();
var Ilist = obj.SelectAll();
foreach (EML.Models.SpNewsCommentsLikes_SelectAll_Result row in Ilist){
var TotalCommentLikes = row.CommentDesLike;
context.Response.Write(TotalCommentLikes);
}
和Jquery
function LikeEvent(Comment) {
$(".A1").click(function () {
var CommentiD = $(this).data("id");
if (CommentiD == null) {
var CommentiD = Comment;
}
//var NewsId =41
$.ajax({
type: "POST",
url: '../Searis/Test.ashx?CommentiD=' + CommentiD,
dataType: "json",
//data:{id:CommentiD},
success: function (jsonData) {
var commentLikesTotal = jsonData;
$('.A2,#lblDesLike').text(commentLikesTotal);
}
});
return false;
});
};
问题是jsonData返回01010101010,它用这个值填充每个lblDesLike。我尝试获取lblDesLike id,但它总是取第一个id而不是我点击的那个,所以我不知道如何用自己的价值填充每个lblDesLike。