如何将json静态数据从代码绑定到aspx页面? [英] How to bind json static data from code behind to aspx page?

查看:75
本文介绍了如何将json静态数据从代码绑定到aspx页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将json格式的静态数据从代码传递到aspx页面。

有一个aspx页面,我想传递数据json格式并通过解析代码在aspx页面中获取它。



我该怎么做?



任何帮助都将不胜感激。

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.

推荐答案

你的问题不是很清楚,但我会尝试给你一些提示:

1。如果您希望从代码中将数据传递到您的页面,您应该在下一个示例中执行:



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:

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.如果您希望从您的页面将数据传递到您的页面,并且还要根据您的调用结果从UI更新控件,您应该使用jQuery,如下一个示例所示: br $>




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 ({
类型:POST,
url:action,
data:{itemComment:itemComment1,itemAmount:itemAmount1,itemLength:itemLength1,itemWidth:itemWidth1,itemThickness:itemThickness1},
success:function(resultData){
var quantity = resultData.result;
.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(数量)
},
dataType:json
});
("#computedQuantity").val(quantity) }, dataType: "json" });


这篇关于如何将json静态数据从代码绑定到aspx页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆