jQWidgets Forums
jQuery UI Widgets › Forums › TreeGrid › not working with asp.net mvc 5
Tagged: jqwidgets treegrid, treegrid .net mvc5
This topic contains 2 replies, has 2 voices, and was last updated by xqyi 10 years, 4 months ago.
-
Author
-
in asp.net mvc 5. view code like below:
@{ ViewBag.Title = "资源"; } <script type="text/javascript"> $(document).ready(function () { var employees = [{ "Code": "0db26f25-21ba-4b32-8076-e73cfb7c32a6", "Name": "系统管理", "Description": "", "Icon": "", "Symbol": "", "Sort": "1", "ActiveFlag": "True", Children: [{ "Code": "177ec218-56ec-4bc0-bd26-958fb268bf1b", "Name": "资源维护", "Description": "", "Icon": "", "Symbol": "", "Sort": "1", "ActiveFlag": "True", Children: [{ "Code": "95f1699d-f141-434d-966f-6b87f0142f3c", "Name": "菜单维护", "Description": "", "Icon": "", "Symbol": "/resource/menuresource", "Sort": "1", "ActiveFlag": "True" }] }, { "Code": "b6c0ba42-b46c-4e09-8223-db0090f6fd63", "Name": "系统日志", "Description": "", "Icon": "", "Symbol": "", "Sort": "2", "ActiveFlag": "True" }] }, { "Code": "10415d6f-adae-4b16-8e24-fb5657e1bae2", "Name": "流程管理", "Description": "", "Icon": "", "Symbol": "", "Sort": "2", "ActiveFlag": "True", Children: [{ "Code": "545276c3-49e9-410c-b988-183cd5004bda", "Name": "流程实例", "Description": "", "Icon": "", "Symbol": "", "Sort": "1", "ActiveFlag": "True" }, { "Code": "f9326efa-831b-4484-bf36-ef55b29ff89b", "Name": "流程异常", "Description": "", "Icon": "", "Symbol": "", "Sort": "2", "ActiveFlag": "True" }] }, { "Code": "d43d500a-c6bf-4a31-ab9f-406056197b12", "Name": "运维平台", "Description": "", "Icon": "", "Symbol": "", "Sort": "3", "ActiveFlag": "True", Children: [{ "Code": "202abe2f-8cc3-4726-9ae8-7b03dd8cf8db", "Name": "流程实例", "Description": "", "Icon": "", "Symbol": "", "Sort": "1", "ActiveFlag": "True" }, { "Code": "2fed4ecb-7a06-4c0b-91b5-d2e4cc335cbb", "Name": "流程异常", "Description": "", "Icon": "", "Symbol": "", "Sort": "2", "ActiveFlag": "True" }] }]; // prepare the data var source = { dataType: "json", dataFields: [ { name: 'Code', type: 'string' }, { name: 'Name', type: 'string' }, { name: 'Description', type: 'string' }, { name: 'Icon', type: 'string' }, { name: 'Symbol', type: 'string' }, { name: 'Sort', type: 'string' }, { name: 'Children', type: 'array' }, { name: 'ActiveFlag', type: 'string' } ], hierarchy: { root: 'Children' }, id: 'Code', //url: '/Resource/GetAllMenuResource' localData: employees }; var dataAdapter = new $.jqx.dataAdapter(source); // create Tree Grid $("#treeGrid").jqxTreeGrid( { width: '100%', source: dataAdapter, sortable: true, columns: [ { text: '菜单编码', dataField: 'Code', hidden: true, align: 'center' }, { text: '菜单名称', dataField: 'Name', align: 'center' }, { text: '菜单描述', dataField: 'Description', align: 'center' }, { text: '菜单图标', dataField: 'Icon', align: 'center' }, { text: '排序序号', dataField: 'Sort', align: 'center' }, { text: '菜单标识', dataField: 'Symbol', align: 'center' }, { text: '是否激活', dataField: 'ActiveFlag', width: 80, align: 'center' } ] }); }); </script> <div id="treeGrid"> </div>
use localdata in srouce is working fine, but when use url to get json data from a mvc controler there is no data to display. the controller code like below:
public string GetAllMenuResource() { return "[{ \"Code\": \"0db26f25-21ba-4b32-8076-e73cfb7c32a6\", \"Name\": \"系统管理\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"1\", \"ActiveFlag\": \"True\", Children: [{ \"Code\": \"177ec218-56ec-4bc0-bd26-958fb268bf1b\", \"Name\": \"资源维护\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"1\", \"ActiveFlag\": \"True\", Children: [{ \"Code\": \"95f1699d-f141-434d-966f-6b87f0142f3c\", \"Name\": \"菜单维护\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"/resource/menuresource\", \"Sort\": \"1\", \"ActiveFlag\": \"True\" }] }, { \"Code\": \"b6c0ba42-b46c-4e09-8223-db0090f6fd63\", \"Name\": \"系统日志\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"2\", \"ActiveFlag\": \"True\" }] }, { \"Code\": \"10415d6f-adae-4b16-8e24-fb5657e1bae2\", \"Name\": \"流程管理\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"2\", \"ActiveFlag\": \"True\", Children: [{ \"Code\": \"545276c3-49e9-410c-b988-183cd5004bda\", \"Name\": \"流程实例\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"1\", \"ActiveFlag\": \"True\" }, { \"Code\": \"f9326efa-831b-4484-bf36-ef55b29ff89b\", \"Name\": \"流程异常\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"2\", \"ActiveFlag\": \"True\" }] }, { \"Code\": \"d43d500a-c6bf-4a31-ab9f-406056197b12\", \"Name\": \"运维平台\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"3\", \"ActiveFlag\": \"True\", Children: [{ \"Code\": \"202abe2f-8cc3-4726-9ae8-7b03dd8cf8db\", \"Name\": \"流程实例\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"1\", \"ActiveFlag\": \"True\" }, { \"Code\": \"2fed4ecb-7a06-4c0b-91b5-d2e4cc335cbb\", \"Name\": \"流程异常\", \"Description\": \"\", \"Icon\": \"\", \"Symbol\": \"\", \"Sort\": \"2\", \"ActiveFlag\": \"True\" }] }]"; }
what can i do to make this work?
Hello xqui,
Working demo with ASP .NET MVC5 is available on this page: http://mvcexamples.jqwidgets.com/widgets/treegrid/arctic. If your client-server communication fails, then I would suggest you to look for the problem there and I also suggest you to look at the demo I sent you.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/thanks peter.
the demo is working fine for me, my controller return a string value not a json value because I don’t know how to generate a nested json data object to return to client.
I changed my controller to return a jsonresult to client, it’s working now! thanks.
-
AuthorPosts
You must be logged in to reply to this topic.