【发布时间】:2016-02-12 16:38:17
【问题描述】:
使用 Telerik DataAccess,我的数据库中有一个名为 chkSomething 的 Numeric(1,0) 字段,它在历史上用于确定复选框的状态(你知道,三态)
0 - Unchecked
1 - Checked
2 - Neither Checked nor Unchecked
但是 Kendo 复选框只是一个 2-State 复选框。所以我想我可以扩展模型:
public partial class TripleCheckboxModel
{
private int _ID;
public int ID {
get { return this._ID; }
set { this._ID = value; }
}
private int _chkSomething;
public int ChkSomething {
get { return this._chkSomething; }
set { this._chkSomething = value; }
}
[NotMapped]
public bool BoolChkSomething {
get { return (this.ChkSomething == 1); }
set { this._chkSomething = (value) ? 1 : 0; }
}
}
在客户端完美运行:
@(Html.Kendo().CheckBoxFor(m => m.BoolChkSomething)
但是,在像这样切换复选框后调用 CRUD 操作时:
public ActionResult chk_Update([DataSourceRequest] DataSourceRequest request, TripleCheckboxModel updateItem)
{
TripleCheckboxModel originalItem = this.dbContext.TripleCheckboxModels.FirstOrDefault(q => q.ID == updateItem.ID);
// Here you can see the Issus
originalItem.BoolChkSomething = updateItem.BoolChkSomething;
this.dbContext.SaveChanges();
return ...
}
它不会返回客户端选择的实际状态,而是在加载项目时最初设置的状态。我很难跟踪这个问题,因为似乎在将 JSON 转换回 TripleCheckboxModel 时,BoolChkSomething 属性中的设置器不会被调用(或在分配 ChkSomething 属性时被覆盖)。
有没有一种(更简单的)方法可以让它运行? (不改变数据库,因为它被另一个应用程序使用)
【问题讨论】:
标签: asp.net-mvc telerik telerik-mvc