我正在建立一个基于MVC的网站,带有一个SQL数据库& ASP.Net 4
不确定我缺少什么,但我正在尝试使用Kendo UI框架显示可更新的表。
请参阅下面的
控制器:
/// <summary>
/// Reads the available products to provide data for the Kendo Grid
/// </summary>
/// <returns>All available products as 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 to do paging
// Use a view model to avoid serializing internal Entity Framework properties as 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);
}
}
查看
@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 From Date").Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.CUST_UpdateFromSupplier_010859867).Title("Update From Supplier");
columns.Bound(p => p.CUST_UpdateFromSupplierDate_010930291).Title("Update From 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>
答案 0 :(得分:0)
编辑:尝试修改您的操作方法以获得以下签名。您还需要使用Kendo.Mvc.UI
命名空间。
[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 to do paging
// Use a view model to avoid serializing internal Entity Framework properties as 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);
}
}
您的操作方法仅接受HTTP POST。您的数据源配置需要如下:
@(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 From Date").Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.CUST_UpdateFromSupplier_010859867).Title("Update From Supplier");
columns.Bound(p => p.CUST_UpdateFromSupplierDate_010930291).Title("Update From 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");
})
)
)
答案 1 :(得分:0)
我移动了kendo.aspnetmvc.min.js位于Kendo捆绑包的底部,根据其网站上的故障排除。
然后我改变了读取操作以匹配控制器的名称,而不是它;
.Read(read =&gt; read.Action(&#34; Read&#34;,&#34; UpdateJSONTest&#34;)。输入(HttpVerbs.Post))
我感到困惑,因为剑道的样本说&#34; Grid&#34;我以为我本来是要使用网格的名称,而不是控制器。