asp.net - JSON Not Returning Any Results -
i building website based on mvc sql database & asp.net 4
not sure missing trying display table updateable using kendo ui framework.
please see below
controller:
/// <summary> /// reads available products provide data kendo grid /// </summary> /// <returns>all available products json</returns> [httppost] public actionresult read(int take, int skip, ienumerable<sort> sort, kendo.dynamiclinq.filter filter) { using (var db = new sc_newentities12()) { var result = db.sc_opportunities .orderby(p => p.cust_intranetdate_093808085) // ef requires ordered iqueryable in order paging // use view model avoid serializing internal entity framework properties json .select(p => new updateviewmodel { manageuserid = p.manageuserid, cust_customer_070539405 = p.cust_customer_070539405, cust_make_093929971 = p.cust_make_093929971, cust_model_093950750 = p.cust_model_093950750, cust_currentsupplier_100623404 = p.cust_currentsupplier_100623404, cust_currentdealer_100741601 = p.cust_currentdealer_100741601, cust_updatefromsupplier_010859867 = p.cust_updatefromsupplier_010859867, cust_updatefromsupplierdate_010930291 = p.cust_updatefromsupplierdate_010930291, cust_carestimateddeliverydate_121235253 = p.cust_carestimateddeliverydate_121235253, cust_intranetdate_093808085 = p.cust_intranetdate_093808085, link2contact = p.link2contact, link2opportunity = p.link2opportunity, stageid = p.stageid, e_mail = p.e_mail, status = p.status }) .todatasourceresult(take, skip, sort, filter); return json(result); } }
view
@model ienumerable<intranetef6.models.sc_opportunities> @{ viewbag.title = "update json test"; } <h2>update json test</h2> <div id="clientsdb"> @(html.kendo().grid<intranetef6.models.sc_opportunities>() .name("grid") .columns(columns => { columns.bound(p => p.cust_intranetdate_093808085).title("intranet date").format("{0:dd/mm/yyyy}"); columns.bound(p => p.manageuserid).title("sales person").clienttemplate("#if(data.manageuserid.tostring() == 'c37ac75b-286d-430a-af50-8d3dffa8b1ee') " + "{#<div>daren</div>#} " + "if(data.manageuserid.tostring() == '1acb3e5a-81ed-4cb4-a68f-094939f0efa4') " + "{#<div>david</div>#} " + "if(data.manageuserid.tostring() == '739f07c5-defe-4395-a93e-51adc7f410ff') " + "{#<div>dee</div>#} " + "if(data.manageuserid.tostring() == 'ca3dfb36-0efe-43df-9801-7602a0b112ae') " + "{#<div>james</div>#} " + "if(data.manageuserid.tostring() == 'a88a8884-3133-4ca5-bf82-cd4b87eb12cb') " + "{#<div>jamie</div>#} " + "if(data.manageuserid.tostring() == 'e317009f-cde0-49c2-80dc-da3ce9c40b3b') " + "{#<div>mark</div>#} " + "if(data.manageuserid.tostring() == '58d0e41d-904b-4c93-8ac7-424b5370fe2e') " + "{#<div>paul</div>#} " + "if(data.manageuserid.tostring() == '28457a43-ebc2-490f-b423-db1fdaa3d3b5') " + "{#<div>richard</div>#} " + "if(data.manageuserid.tostring() == 'c5474c7e-a829-4a0e-af07-8e0614bb3cc4') " + "{#<div>rowan</div>#} " + "if(data.manageuserid.tostring() == 'fac58484-8b20-4b97-8eb8-5d060db84d93') " + "{#<div>russell</div>#} " + "if(data.manageuserid.tostring() == 'b3fc40ae-b547-4f59-b651-ba30dbe60d1a') " + "{#<div>sam bryan</div>#} " + "if(data.manageuserid.tostring() == '8fb9c8b4-bfe2-42ce-aa5b-d2cbbf96f186') " + "{#<div>santi</div>#} " + "if(data.manageuserid.tostring() == 'dc8cd950-d4cc-4c5f-9ab0-867dbf13d61b') " + "{#<div>shane</div>#} " + "if(data.manageuserid.tostring() == '42182f43-f8a3-41d8-bcac-70fcc9942027') " + "{#<div>steve</div>#} " + "if(data.manageuserid.tostring() == 'e93c7603-b49e-4f53-acdb-9847ba407efa') " + "{#<div>yasir</div>#} " + "if(data.manageuserid.tostring() == 'd8c83978-4aeb-49a8-8b6c-f3e5dbba4288') " + "{#<div>jenny</div>#} " + "if(data.manageuserid.tostring() == 'c48c2aec-cdf2-427b-a18b-ce6e7499fa86') " + "{#<div>harry</div>#} " + "if(data.manageuserid.tostring() == '6efc7514-d8ef-446e-85b8-0246b168d5cc') " + "{#<div>sam malik</div>#} #"); columns.bound(p => p.cust_customer_070539405).title("customer"); columns.bound(p => p.cust_make_093929971).title("make"); columns.bound(p => p.cust_model_093950750).title("model"); columns.bound(p => p.cust_currentsupplier_100623404).title("funder"); columns.bound(p => p.cust_currentdealer_100741601).title("dealer"); columns.bound(p => p.cust_carestimateddeliverydate_121235253).title("order date").format("{0:dd/mm/yyyy}"); columns.bound(p => p.cust_updatefromsupplier_010859867).title("update supplier"); columns.bound(p => p.cust_updatefromsupplierdate_010930291).title("update supplier date").format("{0:dd/mm/yyyy}"); columns.bound(p => p.link2contact).title("act! contact").clienttemplate(@"<a href=#=link2contact#>open contact</a>"); columns.bound(p => p.link2opportunity).title("act! opp").clienttemplate(@"<a href=#=link2opportunity#>open opp</a>"); }) .htmlattributes(new { style = "height: 380px;" }) .scrollable() .sortable() .pageable() .datasource(datasource => datasource .ajax() .pagesize(400) .read(read => read.action("read", "grid")) ) ) </div>
edit: try modifying action method have following signature. need using kendo.mvc.ui
namespace.
[httppost] public actionresult read([datasourcerequest]datasourcerequest datasourcerequest) { using (var db = new sc_newentities12()) { var result = db.sc_opportunities .orderby(p => p.cust_intranetdate_093808085) // ef requires ordered iqueryable in order paging // use view model avoid serializing internal entity framework properties json .select(p => new updateviewmodel { manageuserid = p.manageuserid, cust_customer_070539405 = p.cust_customer_070539405, cust_make_093929971 = p.cust_make_093929971, cust_model_093950750 = p.cust_model_093950750, cust_currentsupplier_100623404 = p.cust_currentsupplier_100623404, cust_currentdealer_100741601 = p.cust_currentdealer_100741601, cust_updatefromsupplier_010859867 = p.cust_updatefromsupplier_010859867, cust_updatefromsupplierdate_010930291 = p.cust_updatefromsupplierdate_010930291, cust_carestimateddeliverydate_121235253 = p.cust_carestimateddeliverydate_121235253, cust_intranetdate_093808085 = p.cust_intranetdate_093808085, link2contact = p.link2contact, link2opportunity = p.link2opportunity, stageid = p.stageid, e_mail = p.e_mail, status = p.status }) .todatasourceresult(datasourcerequest); return json(result); } }
your action method accepts http post. data source configuration needs follows:
@(html.kendo().grid<intranetef6.models.sc_opportunities>() .name("grid") .columns(columns => { columns.bound(p => p.cust_intranetdate_093808085).title("intranet date").format("{0:dd/mm/yyyy}"); columns.bound(p => p.manageuserid).title("sales person").clienttemplate("#if(data.manageuserid.tostring() == 'c37ac75b-286d-430a-af50-8d3dffa8b1ee') " + "{#<div>daren</div>#} " + "if(data.manageuserid.tostring() == '1acb3e5a-81ed-4cb4-a68f-094939f0efa4') " + "{#<div>david</div>#} " + "if(data.manageuserid.tostring() == '739f07c5-defe-4395-a93e-51adc7f410ff') " + "{#<div>dee</div>#} " + "if(data.manageuserid.tostring() == 'ca3dfb36-0efe-43df-9801-7602a0b112ae') " + "{#<div>james</div>#} " + "if(data.manageuserid.tostring() == 'a88a8884-3133-4ca5-bf82-cd4b87eb12cb') " + "{#<div>jamie</div>#} " + "if(data.manageuserid.tostring() == 'e317009f-cde0-49c2-80dc-da3ce9c40b3b') " + "{#<div>mark</div>#} " + "if(data.manageuserid.tostring() == '58d0e41d-904b-4c93-8ac7-424b5370fe2e') " + "{#<div>paul</div>#} " + "if(data.manageuserid.tostring() == '28457a43-ebc2-490f-b423-db1fdaa3d3b5') " + "{#<div>richard</div>#} " + "if(data.manageuserid.tostring() == 'c5474c7e-a829-4a0e-af07-8e0614bb3cc4') " + "{#<div>rowan</div>#} " + "if(data.manageuserid.tostring() == 'fac58484-8b20-4b97-8eb8-5d060db84d93') " + "{#<div>russell</div>#} " + "if(data.manageuserid.tostring() == 'b3fc40ae-b547-4f59-b651-ba30dbe60d1a') " + "{#<div>sam bryan</div>#} " + "if(data.manageuserid.tostring() == '8fb9c8b4-bfe2-42ce-aa5b-d2cbbf96f186') " + "{#<div>santi</div>#} " + "if(data.manageuserid.tostring() == 'dc8cd950-d4cc-4c5f-9ab0-867dbf13d61b') " + "{#<div>shane</div>#} " + "if(data.manageuserid.tostring() == '42182f43-f8a3-41d8-bcac-70fcc9942027') " + "{#<div>steve</div>#} " + "if(data.manageuserid.tostring() == 'e93c7603-b49e-4f53-acdb-9847ba407efa') " + "{#<div>yasir</div>#} " + "if(data.manageuserid.tostring() == 'd8c83978-4aeb-49a8-8b6c-f3e5dbba4288') " + "{#<div>jenny</div>#} " + "if(data.manageuserid.tostring() == 'c48c2aec-cdf2-427b-a18b-ce6e7499fa86') " + "{#<div>harry</div>#} " + "if(data.manageuserid.tostring() == '6efc7514-d8ef-446e-85b8-0246b168d5cc') " + "{#<div>sam malik</div>#} #"); columns.bound(p => p.cust_customer_070539405).title("customer"); columns.bound(p => p.cust_make_093929971).title("make"); columns.bound(p => p.cust_model_093950750).title("model"); columns.bound(p => p.cust_currentsupplier_100623404).title("funder"); columns.bound(p => p.cust_currentdealer_100741601).title("dealer"); columns.bound(p => p.cust_carestimateddeliverydate_121235253).title("order date").format("{0:dd/mm/yyyy}"); columns.bound(p => p.cust_updatefromsupplier_010859867).title("update supplier"); columns.bound(p => p.cust_updatefromsupplierdate_010930291).title("update supplier date").format("{0:dd/mm/yyyy}"); columns.bound(p => p.link2contact).title("act! contact").clienttemplate(@"<a href=#=link2contact#>open contact</a>"); columns.bound(p => p.link2opportunity).title("act! opp").clienttemplate(@"<a href=#=link2opportunity#>open opp</a>"); }) .htmlattributes(new { style = "height: 380px;" }) .scrollable() .sortable() .pageable() .datasource(datasource => datasource .ajax() .pagesize(400) .read(read => { read.type(httpverbs.post); read.action("read", "grid"); }) ) )
Comments
Post a Comment