views:

30

answers:

1

Hi all,

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

My problem is, that while I can 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; }
}
A: 

Hi all,

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>";
    }
}
Anders Juul