kendo-grid - Kendo UI 网格与下拉编辑器模板编辑问题

标签 kendo-grid edit mvc-editor-templates dropdownlistfor

我有一个带有两个下拉列表列的网格,它们与 Razor 页面中的编辑器模板进行映射。所有单一编辑和更新都工作正常,没有任何问题。但是,当我单击第一行进行编辑并尝试编辑第二行而不更新或取消第一行时,它会自动关闭第一行的编辑模式,第二行可编辑。这很好,但是当我单击返回第一行而不更新或取消第二行时,第二行的值也会在第一行中更新。

我该如何阻止这个问题。顺便说一下,它是测试人员发现的,而不是我..:(

当我们尝试编辑多行而不更新或取消事件的可编辑行时,所有问题都会出现。

请帮助我,因为我花了很多时间。我在此处附加示例代码......字段名称和模板名称已修改以给出简单的示例。

网格

@(Html.Kendo().Grid(Model.Employees)
              .Name("GridEmployees")
              .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"))
              )
              )

编辑器模板

季度.cshtml

@using System.Collections

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

频率.cshtml

@使用System.Collections

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

提前致谢,

最佳答案

迟到总比不到好……问题是,您生成了多个具有相同 id 的下拉列表。只需为 EditorTemplate 中的下拉列表分配一个动态 ID 就可以了。

@(Html.Kendo().DropDownListFor(i => i)
            .Name("Frequency")
            .HtmlAttributes(new { @id = "Frequency_#=UniqueId#" }) //eg. row id
            .DataValueField("Id")
            .DataTextField("Name")
            .BindTo((IEnumerable)ViewBag.Frequencies)
            .OptionLabel("Select Frequency")
 )

关于kendo-grid - Kendo UI 网格与下拉编辑器模板编辑问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25754965/

相关文章:

asp.net-mvc - 在 ASP.NET MVC 中将 DateTime 拆分为日期和时间

asp.net-mvc - DisplayFormat 未应用于十进制值

c# - IEnumerable 的 MVC3 编辑器模板不会在 @Html.LabelFor 中生成 'for' 属性

javascript - 禁用 KendoGrid 中过滤列的动画

javascript - 在 JQuery 或 JavaScript 中的 Grid 标题上生成 onClick 事件

javascript - 编辑传单中的功能属性

batch-file - 是否可以使用批处理脚本编辑.Config 文件

php - 按行编辑表格

javascript - 这是 Kendo Ui Grid 错误吗?

html - Kendo UI Grid——将日期排序为字符串