【发布时间】: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) 参数包含所有已修改状态的条目。但是,即使该州没有任何城市,各州也有一个包含一个城市(为空)的城市列表。
所以关键是我没有在我的代码的任何部分创建任何城市,但是当我收到状态作为上面列出的控制器操作的参数时,城市列表中存在一个空城市。为什么会这样?
【问题讨论】: