Telerik kendo MVC子网格与编辑poup相结合

时间:2016-04-29 07:57:24

标签: asp.net-mvc telerik

我有一个带有基于MVC的子网格的kendo网格,使用弹出模式可以编辑数据。一切正常, 但是当我添加一个子行程时,我希望已经填充了父表的相关字段。 我的代码如下所示:

    <script id="subGrid" type="text/kendo-tmpl">
@(Html.Kendo().Grid<SiennInvoice.Models.InvoiceModel>()
        .Name("grid_#=ID#") // template expression, to be evaluated in the master context
          .Columns(columns =>
          {
              columns.Bound(c => c.Description);
              columns.ForeignKey(c => c.IntervalType, (System.Collections.IEnumerable)ViewBag.IntervalTypesDdl, "Value", "Text");
              columns.Bound(c => c.Interval);
              columns.Bound(c => c.Amount);
              columns.Bound(c => c.InvoiceDate);
              columns.ForeignKey(c => c.Currency, (System.Collections.IEnumerable)ViewBag.CurrenciesDdl, "Value", "Text");
              columns.Bound(c => c.Done);
              columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
          })
        .ToolBar(toolbar => toolbar.Create())
        .Editable(editable => editable.Mode(GridEditMode.PopUp))
        .Pageable()
        .Sortable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(10)
            .Read(read => read.Action("HierarchyBinding_Invoices", "OrderEdit", new { OrderId = "#=ID#" }))

            .Events(events => events.Error("error_handler"))
            //.Model(model => model.Id(o => o.ID))
            .Model(model =>
            {
                model.Id(o => o.ID);
                model.Field(field => field.OrderId).DefaultValue("#=ID#");
            })
          //.Create(create => create.Action("Invoice_Create", "OrderEdit"))
          //.Update(update => update.Action("Invoice_Update", "OrderEdit"))
          //.Destroy(destroy => destroy.Action("Invoice_Destroy", "OrderEdit"))
          //.Read(read => read.Action("Invoices_Read", "ToBeInvoiced"))
          .Create(create => create.Action("Invoices_Create", "ToBeInvoiced"))
          .Update(update => update.Action("Invoices_Update", "ToBeInvoiced"))
          .Destroy(destroy => destroy.Action("Invoices_Destroy", "ToBeInvoiced"))
        )
        .ToClientTemplate()
)
</script>

问题出在DefaultValue中,我不能像在读取操作中那样使用“#= ID”, 这引起了一个错误。 但是,我可以使用1,2或3,但我希望每行动态。

有人可以帮我吗? 谢谢。

1 个答案:

答案 0 :(得分:0)

我试着用这种方式:

  1. 编写我自己的PopUp EditTemplate并包含标记
  2. <input type="hidden" name="OrderId" id="OrderId"/>

    1. 添加活动

      .Events(events => events.Edit("function(e){e.model.OrderId='#=OrderId#';}"));