Hi, I have a problem, and I’ve cracked it for several hours, I always get an error
Cannot set property or index to 'AnonymousType # 1.XP' - it is read-only
The problem arises on a.XP here
foreach (var a in comments)
{
a.XP = score.getLevel(a.XP);
}
and as a comment pointed out that I never say what I want to do, I would like to replace a.XP with an improved score.getLevel (a.XP) value.
Here is the complete code
protected void GetComments()
{
TimberManiacsDataContext db = new TimberManiacsDataContext();
Score score = new Score();
var comments = (from fComment in db.Comments
where fComment.PublishID == Convert.ToInt32(Request.QueryString["Article"])
orderby fComment.DateTime descending
select new
{
UserName = fComment.User.UserLogin.Username,
PostTime = fComment.DateTime,
UserImage = fComment.User.UserGeneralInfo.ProfilePicture,
Comment = fComment.Comment1,
UserID = fComment.UserID,
XP = fComment.User.CommunityScore
}).Take(10).ToList();
foreach (var a in comments)
{
a.XP = score.getLevel(a.XP);
}
Commentlist.DataSource = comments;
Commentlist.DataBind();
}
source
share