Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to pass the static data in json format from code behind to the aspx page.
have a aspx page and I want to pass the data in json format and get it in aspx page by parsing the code.

How can I do that?

Any help would be appreciated.
Posted
Updated 21-Mar-14 23:34pm
v4

1 solution

Your question is not so clear but I will try to give you some hints:
1.If you want from your code to pass data to your page you should do like in the next example:

C#
var result = new
    {
        total = (int)Math.Ceiling((double)count / grid.PageSize),
        page = grid.PageIndex,
        records = count,
        rows = (from host in data
                select new
                {
                    ID = host.ID,
                    VisitorName = GetVisitorNameForBinding(host),
                    StartDate = host.StartDate.ToString(),
                    EndDate = host.EndDate.ToString(),
                    WasTimeOut = (host.WasTimeOut ?? false)
                                
                }).ToArray()
    };
    //
    // Convert to JsonResult before to return.
    //
    return Json(result, JsonRequestBehavior.AllowGet);


2.If you want from your page to pass data to your page and also to update the control from UI with the result from your call, you should use jQuery like in the next example:

function computeWithJson(action, itemComment1, itemAmount1, itemLength1, itemWidth1, itemThickness1) {
    $.ajax({
        type: "POST",
        url: action,
        data: { itemComment: itemComment1, itemAmount: itemAmount1, itemLength: itemLength1, itemWidth: itemWidth1, itemThickness: itemThickness1 },
        success: function (resultData) {
            var quantity = resultData.result;
            $("#computedQuantity").val(quantity)
        },
        dataType: "json"
    });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900