我有一个 KendoUI 网格,它允许用户使用内联模式更新值。问题是我有两个不允许空值的双重属性,但是 NumericTextBox 让我设置一个空值,然后接受它,如下图所示:
如果您按下“Aceptar”(“接受”)按钮,输入保持为空,但它在数据库中保存“0”,您只有在刷新页面时才能看到它。这是网格的代码:
@(Html.Kendo().Grid<ReferenceThresholdVM>()
.Name("grdReference")
.Columns(columns =>
{
columns.Bound(t => t.txbTransponderName).Title("Transponder").Width(120);
columns.Bound(t => t.txbDataSourceName).Title("Variable").Width(200);
columns.ForeignKey(t => t.ddlReferenceTypeId, ReferenceTypeVM.GetComboList(), "Id", "Description").Title("Modo").Width(110);
columns.Bound(t => t.ntbThreshold).Title("Umbral").Width(100);
columns.Bound(t => t.ntbCurrentValue).Title("Valor de referencia").Format("{0:n2}").Width(170);
columns.Bound(t => t.ntbHysteresis).Title("Histeresis").Format("{0:n2}").Width(100);
columns.Bound(t => t.ntbThresholdTrigger).Title("Umbral de disparo").Format("{0:n2}").Width(150);
columns.Command(command =>
{
command.Edit().CancelText("Cancelar").UpdateText("Confirmar");
command.Destroy();
}).Width(220).HtmlAttributes(new { style = "text-align: center;" });
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Navigatable()
.Sortable()
.Events(e => e.Save("onSave"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(12)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(t => t.Id);
model.Field(t => t.Id);
model.Field(t => t.txbTransponderName).Editable(false);
model.Field(t => t.txbDataSourceName).Editable(false);
model.Field(t => t.ddlReferenceTypeId);
model.Field(t => t.ntbThreshold);
model.Field(t => t.ntbHysteresis);
model.Field(t => t.ntbCurrentValue).Editable(false);
model.Field(t => t.ntbThresholdTrigger).Editable(false);
})
.Read(read => read
.Action("Read_Reference", "Reference")
.Data("getFilterReference")
)
.Update("Reference_Update", "Reference")
.Destroy("Reference_Destroy", "Reference")
)
.Events(events => events.DataBound("onGrdReferenceDataBound"))
.AutoBind(false)
)
每个属性都是通过使用 UIHint 定义的,该 UIHint 定义了输入的一些行为:
[Display(Name = "Umbral")]
[UIHint("PositiveNumber")]
public double ntbThreshold
{
get;
set;
}
[Display(Name = "Histeresis")]
[UIHint("PositiveNumber")]
public double ntbHysteresis
{
get;
set;
}
最后这是 UIHint "PositiveNumber" 的代码:
@model int?
@(Html.Kendo().NumericTextBoxFor(m => m)
.HtmlAttributes(new { @class = "k-numerictextbox" })
.Min(0)
.Max(int.MaxValue)
.Value(0)
)
有没有办法禁用让 NumericTextBox 为空的可能性?