[英]Kendo UI Grid returns JSON to browser (using MVC)
I've recently purchased a Kendo subscription, I'm having trouble getting an AJAX bound grid to operate as expected, hoping someone here can help. 我最近购买了一个Kendo订阅,我无法让AJAX绑定网格按预期运行,希望有人在这里可以提供帮助。
I have followed the Kendo docs tutorial @ http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding and could get the AJAX binding working nicely. 我已经关注了Kendo文档教程@ http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding ,可以很好地使AJAX绑定工作。
I've tried to now implement it into an existing MVC solution, and whenever I click the New or Edit command button, I get a string of JSON returned to the browser . 我已经尝试将其实现到现有的MVC解决方案中,每当我单击New或Edit命令按钮时, 我都会将一个JSON字符串返回给浏览器 。 Similiar to issue ( JSON data to KENDO UI Grid ASP.NET MVC 4 ) But the answer in that problem didn't work for me. 类似于问题( JSON数据到KENDO UI Grid ASP.NET MVC 4 )但是这个问题的答案对我不起作用。
Here is my Controller code... 这是我的控制器代码......
public ActionResult Index()
{
// non-important code removed here //
var viewModel = newReferenceViewModel();
ViewBag.TradeReferences = TradeReferenceWorker.Get(applicationId);
return View(viewModel);
}
public ActionResult TradeReferences_Read([DataSourceRequest]DataSourceRequest request)
{
var applicationId = GetCurrentApplicationId();
DataSourceResult result = TradeReferenceWorker.Get(applicationId).ToDataSourceResult(request);
return Json(result, "text/x-json", JsonRequestBehavior.AllowGet);
}
And the View .... 而观点....
@(Html.Kendo().Grid((IEnumerable<TradeReference>)ViewBag.TradeReferences)
.Name("gridTradeReference")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(tradeReference => tradeReference.TradeReferenceId);
model.Field(tradeReference => tradeReference.TradeReferenceId).Editable(false);
})
.Read(read => read.Action("TradeReferences_Read", "References"))
.Create(create => create.Action("TradeReference_Create", "References"))
.Update(update => update.Action("TradeReference_Update", "References"))
.Destroy(destroy => destroy.Action("TradeReference_Destroy", "References"))
)
.Columns(columns =>
{
columns.Bound(tref => tref.TradeReferenceId).Visible(false);
columns.Bound(tref => tref.Name);
columns.Bound(tref => tref.Phone);
columns.Command(commands =>
{
commands.Edit();
commands.Destroy();
}).Title("").Width(200);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable()
) )
So to sum up... the Grid will load perfectly the first time. 总结一下...... Grid将首次完美加载。 I haven't wired up anything on the Edit / Delete actions, just trying to get Create operational. 我没有在编辑/删除操作上连接任何内容,只是尝试让Create运行。 Clicking Add New, or even Edit for that matter will make the browser simply display Json to the screen. 单击“添加新”,甚至“编辑”将使浏览器只显示Json到屏幕。
It is hopefully something simple - thanks in advance 希望这很简单 - 提前感谢
Solved it - the problem was the kendo js files were not being referenced correctly. 解决了 - 问题是没有正确引用kendo js文件。
In my particular case, the bundling wasn't done 100% correctly so the Kendo javascript files were never getting included in the page. 在我的特定情况下,捆绑没有100%正确完成,因此Kendo javascript文件永远不会被包含在页面中。
They must also appear in a certain order, as described in the troubleshooting guide http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting 它们还必须按照特定顺序出现,如故障排除指南中所述http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.