Using Telerik DataAccess, i have a Numeric(1,0) Field on my Database called chkSomething which was historically used to determine the state of a checkbox (you know, the tristate one)
0 - Unchecked
1 - Checked
2 - Neither Checked nor Unchecked
But the Kendo Checkbox is only a 2-State checkbox. So i thought i could just extend the Model:
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; }
}
}
Which works perfectly on client side:
@(Html.Kendo().CheckBoxFor(m => m.BoolChkSomething)
However when invoking a CRUD operation after toggling the checkbox like this one:
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 ...
}
It does not return the actual state the client chose, but the one which was initially set when the Item was loaded. I'm having a hard time tracking this Issue, as It seems that when converting the JSON back to the TripleCheckboxModel the setter from the BoolChkSomething property does not get invoked (or overwritten when the ChkSomething property gets assigned).
Is there a(n easier) way to get this running? (without changing the Database, as it is used by another application)