2

我在 ASP.NET MVC 剃须刀页面中有两个带有下拉编辑器模板列的 Kendo UI 网格。两个网格始终只有一行,并且可以正常编辑和更新。

但是,当用户单击第一个网格编辑并尝试单击第二个网格编辑时,编辑器模板不适用于第二个网格。它在文本框中显示网格值。两个网格共享相同的列编辑器模板。浏览器控制台中没有错误。

我尝试在部分视图中移动这些网格,并尝试为每个网格创建不同的编辑器模板,但结果总是相同的。

有趣的是,如果您先在第二个网格中进行编辑,然后单击第一个网格编辑,则不会产生任何问题,并会使用编辑器模板显示所有下拉值。(第一个和第二个网格是从上到下的意思)

两个网格都有不同的模型,但模型共享相同的类。

我在这里给出示例代码..请帮助我..已经花了很多时间在这上面。

@model ProjectName.ViewModel.EmployeesViewModel

    @(Html.Kendo().Grid(Model.CasualEmployees)
                  .Name("GridCasualEmployees")
                  .Columns(columns =>
                  {
                      columns.Bound(i => i.Frequency).Title("Frequency").EditorTemplateName("Frequency").ClientTemplate("#:Frequency#").HtmlAttributes(new { @style = "text-align:Left; " }).Width(75);
                      columns.Bound(i => i.Quarter).Title("Quarter").EditorTemplateName("Quarter").ClientTemplate("#= kendo.toString(Quarter,\"MMM yyyy\") #").HtmlAttributes(new { @style = "text-align:left; " }).Width(75);
                      columns.Bound(i => i.EmpId).Hidden();
                      columns.Command(command => command.Edit()).Width(175);
                  })
                  .ToolBar(toolbar => toolbar.Create())
                  .Editable((editable => editable.Mode(GridEditMode.InLine)))
                  .Selectable(selectable => selectable
                      .Mode(GridSelectionMode.Multiple))
                  .Sortable(sortable => sortable
                      .AllowUnsort(true)
                      .SortMode(GridSortMode.MultipleColumn))
                  .DataSource(dataSource => dataSource
                      .Ajax()
                      .Batch(true)
                      .ServerOperation(false)
                      .Model(model =>
                      {
                          model.Id(s => s.EmpId);
                          model.Field(s => s.Frequency);
                          model.Field(s => s.Quarter);
                      })
                      .Create(update => update.Action("CreateEmployee", "Employee"))
                      .Read(read => read.Action("ReadEmployee", "Employee"))
                      .Update(update => update.Action("UpdateEmployee", "Employee"))
                  )
                  )


    @(Html.Kendo().Grid(Model.PermanentEmployees)
                  .Name("GridPermanentEmployees")
                  .Columns(columns =>
                  {
                      columns.Bound(i => i.Frequency).Title("Frequency").EditorTemplateName("Frequency").ClientTemplate("#:Frequency#").HtmlAttributes(new { @style = "text-align:Left; " }).Width(75);
                      columns.Bound(i => i.Quarter).Title("Quarter").EditorTemplateName("Quarter").ClientTemplate("#= kendo.toString(Quarter,\"MMM yyyy\") #").HtmlAttributes(new { @style = "text-align:left; " }).Width(75);
                      columns.Bound(i => i.EmpId).Hidden();
                      columns.Command(command => command.Edit()).Width(175);
                  })
                  .ToolBar(toolbar => toolbar.Create())
                  .Editable((editable => editable.Mode(GridEditMode.InLine)))
                  .Selectable(selectable => selectable
                      .Mode(GridSelectionMode.Multiple))
                  .Sortable(sortable => sortable
                      .AllowUnsort(true)
                      .SortMode(GridSortMode.MultipleColumn))
                  .DataSource(dataSource => dataSource
                      .Ajax()
                      .Batch(true)
                      .ServerOperation(false)
                      .Model(model =>
                      {
                          model.Id(s => s.EmpId);
                          model.Field(s => s.Frequency);
                          model.Field(s => s.Quarter);
                      })
                      .Create(update => update.Action("CreateEmployee", "Employee"))
                      .Read(read => read.Action("ReadEmployee", "Employee"))
                      .Update(update => update.Action("UpdateEmployee", "Employee"))
                  )
                  )




 @(Html.Kendo().DropDownListFor(i => i)
                    .Name("Quarter")
                    .DataValueField("Id")
                    .DataTextField("Name")
                    .BindTo((IEnumerable)ViewBag.Quarters)
                    .OptionLabel("Select Quarter")
    )


        @(Html.Kendo().DropDownListFor(i => i)
                        .Name("Frequency")
                        .DataValueField("Id")
                        .DataTextField("Name")
                        .BindTo((IEnumerable)ViewBag.Frequencies)
                        .OptionLabel("Select Frequency")
        )

     public class EmployeesViewModel
        {
            public List<Employee> CasualEmployees{ get; set; }
            public List<Employee> PermanentEmployees{ get; set; } 
        }

提前致谢,

4

0 回答 0