Extjs4+asp.net mvc2 返回json有问题

猪猪鹏 2011-08-30 03:49:33

public ActionResult testExtJsJson()
{

TreeModel ExtTree1 = new TreeModel();
ExtTree1.id = "1";
ExtTree1.text = "加工工艺管理";
ExtTree1.leaf = true;
ExtTree1.cls = "file";
ExtTree1.href = "";
ExtTree1.children = new List<TreeModel>();


//string json = JsonConvert.SerializeObject(ExtTree1);

//Response.ContentType = "text/html";
//return View();
return this.Json(ExtTree1, JsonRequestBehavior.AllowGet);
//return Content("<pre>" + json+"</pre>", "text/html");
}



Ext.require([
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*'
]);

Ext.onReady(function() {
Ext.QuickTips.init();

var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'Home/testExtJsJson'
},
root: {
text: 'Ext JS',
id: 'src',
expanded: true
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});

var tree = Ext.create('Ext.tree.Panel', {
store: store,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop'
}
},
renderTo: 'tree-div',
height: 300,
width: 250,
title: 'Files',
useArrows: true,
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Expand All',
handler: function(){
tree.expandAll();
}
}, {
text: 'Collapse All',
handler: function(){
tree.collapseAll();
}
}]
}]
});
});


其实就是把官方的例子中的url改了一下!

页面总是显示:{"id":"1","text":"加工工艺管理","cls":"file","expanded":false,"leaf":true,"href":"","children":[]}

用firebug看body中是<pre style="word-wrap: break-word; white-space: pre-wrap; ">{"id":"1","text":"加工工艺管理","cls":"file","expanded":false,"leaf":true,"href":"","children":[]}</pre>

ps:用的是vs2010自带的asp.net mvc2 空项目
...全文
774 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
GeoffreyRen1972 2012-10-19
  • 打赏
  • 举报
回复
http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx
hncdzyl 2012-07-20
  • 打赏
  • 举报
回复
我遇到这个问题两周了!请楼主,高手些指教指教
LK_liukui 2012-04-23
  • 打赏
  • 举报
回复
我遇到这个问题两周了!请楼主,高手些指教指教!
lantian3233 2012-03-21
  • 打赏
  • 举报
回复
我也遇到同样的问题,请问楼主解决了吗?能讲下原因吗?
猪猪鹏 2011-08-30
  • 打赏
  • 举报
回复
有木有人会呀
猪猪鹏 2011-08-30
  • 打赏
  • 举报
回复
只好自己顶了
猪猪鹏 2011-08-30
  • 打赏
  • 举报
回复
高人帮忙解决,已经困扰了2天乐了

110,524

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧