【问题标题】:Telerik MVC3 grid - batch editing issueTelerik MVC3 网格 - 批量编辑问题
【发布时间】:2011-08-14 13:15:13
【问题描述】:

我使用 Telerik MVC Grid 并将其配置为批处理模式编辑http://demos.telerik.com/aspnet-mvc/grid/editingbatch。我正在尝试编辑具有城市列表的实体“州”,其中城市是另一个实体。这是状态实体的外观。

public class State {
    ...Some Scalar Properties
    public virtual List<City> Cities { get; set; }  //Navigation Property
    public State() {  
        Cities = new List<City>();
    }
}

我的城市实体指向下面给出的州。

public class City {
     ... Some Scalar Properties
    public virtual State State { get; set; }  //Navigation property
}

我在我的一个 cshtml 页面中使用这个模型,就像这样

@(Html.Telerik().Grid<State>()
            .Name("tlkStateGrid")
            .Editable(e =>  e.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
            .ToolBar(t => {
                t.Insert().ButtonType(GridButtonType.Image);
                t.SubmitChanges().ButtonType(GridButtonType.Image);
            })

 ...Some More of code here.

在我的控制器中,我以正常方式处理批量更新。

public ActionResult _SaveChanges(IEnumerable<State> inserted, IEnumerable<State> updated, IEnumerable<State> deleted) {
.....
}

当我尝试使用 Telerik Grid 的批处理编辑状态实体时,上述控制器操作的 (IEnumerable updated) 参数包含所有已修改状态的条目。但是,即使该州没有任何城市,各州也有一个包含一个城市(为空)的城市列表。

所以关键是我没有在我的代码的任何部分创建任何城市,但是当我收到状态作为上面列出的控制器操作的参数时,城市列表中存在一个空城市。为什么会这样?

【问题讨论】:

    标签: asp.net-mvc-3 telerik-mvc


    【解决方案1】:

    我不完全确定我理解这个问题。因此,当网格发布时,您会创建一个新的 State。附加到那个 State 对象,有一个空的 City 对象。是这个问题吗?还是我错过了什么?

    如果这是问题所在,这是正常行为,应该可以预料。这就是 MVC3 中自动 JSON 反序列化的工作原理——任何时候创建父对象但未定义嵌套对象,嵌套对象将返回为 null。只需处理代码中的空值即可。

    【讨论】:

    • 感谢您的回复,但我决定不在网格中使用批量编辑。这对用户来说相当混乱。很高兴看到即使经过这么长的差距,这个问题仍然得到了回答。太好了。
    • 没问题,伙计。如果我之前看到这个,我会更早回答。我同意,我认为批量编辑会让用户感到困惑,但我的用户实际上希望编辑过程“更像 Excel”。去图吧。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    相关资源
    最近更新 更多