开发者

c# -> javascript, Json decoding misses property

开发者 https://www.devze.com 2022-12-28 01:17 出处:网络
I have a c# object (below) that I\'m trying to send to my javascript. My problem is, that while I ca开发者_Go百科n iterate over the items in the list, I can\'t get to the string-property (\'Period\')

I have a c# object (below) that I'm trying to send to my javascript.

My problem is, that while I ca开发者_Go百科n iterate over the items in the list, I can't get to the string-property ('Period').

Referencing the object in JS shows no property at all. After Json-encoding in c#, I can still see the property just before returning it to caller (hovering over the result variable in below function):

[OutputCache(Duration = 0, VaryByParam = "None")]
public JsonResult GetRankingList() {
 Response.ContentType = "text/javascript";
 var user = _userService.GetUserByPrincipal(User);

 // Note, we do this while the user waits as we need to make progress in repeated calls to get the compared ranking list.
 _businessLogicServiceMaintenance.PerformMaintenanceSteps();

 //TODO: Replace with userid (Guid)
 var rankingList = _presenterService.GetRankingListForDisplay(user);

 if (rankingList == null)
  return Json("");

 var result = Json(rankingList);
 return result;
}

How on earth can I get past this? Any comments appreciated!

Yours, Anders, Denmark,

public class RankingListForDisplay : List<RankingListLine>
{
    public string Period { get; set; }
}


Thanks for taking your time - I found a solution.

I changed above implementation of RankingListForDisplay to the one below. For some reason json likes it way better ;-)

public class RankingListForDisplay 
{
    public List<RankingListLine> Lines { get; set; }
    public string Period { get; set; }

    public RankingListForDisplay()
    {
        Lines = new List<RankingListLine>();
        Period = "<Unspecified>";
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号