【问题标题】:Model Empty in Popup Editor template for Kendo MVC Grid Create, No default valueKendo MVC Grid Create 的弹出编辑器模板中的模型为空,无默认值
【发布时间】:2017-07-26 17:27:10
【问题描述】:

我有一个 Kendo MVC 层次结构网格。为了便于阅读,我的示例进行了简化。

            @(Html.Kendo().Grid<LeagueViewModel>(Model.Leagues)
        .Name("grid_#=LeagueTypeId#")
        .Columns(columns => { })
        .ToolBar(toolbar =>
        {
            toolbar.Create().Text("Add New League(Window)");
        })
        .Editable(editable => editable.Mode(GridEditMode.PopUp)
            .TemplateName("LeagueEdit")
            .Window(w =>
            {
                w.Position(p => p.Top(200)); // position not working, need to center more vertically
                w.Width(800);
            }
                            )
                        )
        .Events(e => e.Edit("leagueEdit"))
        .DataSource(dataSource => dataSource
            .Server()
            .Model(model =>
            {
                model.Id(p => p.LeagueID);
                model.Field(l => l.strSportId).DefaultValue("#=SportId#"); // set default value with parent grid data
                model.Field(l => l.strLeagueTypeId).DefaultValue("#=LeagueTypeId#"); // set default value with parent grid data
            }
            )
            .Read(read => read.Action("Bound_League_Read", "Configuration", new { _leagueTypeId = "#=LeagueTypeId#" }))
            .Create(create => create.Action("League_Create", "Configuration"))
        )
            )

这是我的 javascript 事件处理程序。在单击创建按钮后从处理程序观察 e.model 对象时,我在网格中使用 DefaultValue("#=ParentProperty#") 设置了我之前设置的默认值。

        function leagueEdit(e) {

                // setting these with default value on model, 
                // had to have string variants to pass over because template expression syntax                  
                e.model.SportId = parseInt(e.model.strSportId);
                e.model.LeagueTypeId = parseInt(e.model.strLeagueTypeId);

                }

LeagueEdit.cshtml 当我的弹出模板打开时,模型没有数据。如何将数据导入模型?我在弹出编辑器中有需要来自父网格的值的元素。

        <p>sport: @Model.SportId</p> <!-- value does not carry over -->
        <p>leaguetype: @Model.LeagueTypeId</p>  <!-- value does not carry over -->  

【问题讨论】:

    标签: kendo-ui kendo-grid kendo-asp.net-mvc telerik-grid telerik-mvc


    【解决方案1】:

    在您的 Edit 事件中,尝试使用其 Id 在弹出窗口中查找控件并设置值。例如,在下面的代码中,我在弹出窗口中找到了一个日期选择器并将其值设置为模型属性。

    function LeagueEditEdit(e) {
        var val1 = e.container.find("input[name=CallDate]").data("kendoDatePicker");
        val1.value($('#CallDate').attr('value'));
        e.model.CallDate = val1._value;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-27
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多