我有一個KendoUI網格,它允許用戶使用內聯模式更新值。問題是,我有兩個雙屬性不允許空值,但不過NumericTextBox給我設置爲空值,然後接受它,因爲你可以在下面的圖片中看到:MVC KendoUI:如何禁用NumericTextBox允許空值?
如果按下「Aceptar」(「Accept」)按鈕,輸入保持爲空,但它會在數據庫中保存「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用於定義輸入一些行爲以這種方式定義:
[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爲空?
您應該立即接受您自己的問題,以防止它顯示爲未解決。 –
你是對的Bruno ...對不起! –