剑道UI电网JSON返回到浏览器(使用MVC) [英] Kendo UI Grid returns JSON to browser (using MVC)

查看:155
本文介绍了剑道UI电网JSON返回到浏览器(使用MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近购买了剑道订阅,我无法得到一个AJAX绑定网格按预期运作,希望这里有人可以提供帮助。

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.

我也跟着剑道文档教程@的http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding
并且可以得到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.

我试过,现在落实到现有的MVC解决方案,每当我点击新建或编辑命令按钮,我得到的JSON字符串返回给浏​​览器即可。类同的问题( JSON数据KENDO UI电网ASP。 NET MVC 4 ),但在这个问题的答案并没有为我工作。

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. Similiar to issue (JSON data to KENDO UI Grid ASP.NET MVC 4) But the answer in that problem didn't work for me.

下面是我的控制器code ...

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);
    } 

和查看......

@(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()

所以总结起来......该电网将完全加载的第一次。我还没有连接起来的任何编辑/删除的操作,只是想获得创造运营。点击添加新的,甚至是编辑为此事将使得浏览器只显示的Json到屏幕上。

So to sum up... the Grid will load perfectly the first time. I haven't wired up anything on the Edit / Delete actions, just trying to get Create operational. Clicking Add New, or even Edit for that matter will make the browser simply display Json to the screen.

这是希望简单的东西 - 在此先感谢

It is hopefully something simple - thanks in advance

推荐答案

解决这 - 问题是剑道js文件没有被正确地引用。

Solved it - the problem was the kendo js files were not being referenced correctly.

在我的具体情况,捆绑却没有这样做100%的正确以便JavaScript的从未得到包含在页面文件中的剑道。

In my particular case, the bundling wasn't done 100% correctly so the Kendo javascript files were never getting included in the page.

他们还必须出现在一定的顺序,故障诊断指南<一中描述href=\"http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting\" rel=\"nofollow\">http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting

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

这篇关于剑道UI电网JSON返回到浏览器(使用MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆