Asp.net mvc MVC KendoUI:如何禁用允许空值的NumericTextBox?
我有一个KendoUI网格,允许用户使用内联模式更新值。问题是我有两个double属性不允许空值,但是NumericTextBox允许我设置一个空值,然后接受它,如下图所示: 如果按“Aceptar”(“Accept”)按钮,输入将保持为空,但它会将“0”保存在数据库中,并且只有在刷新页面时才能看到它。 这是网格的代码:Asp.net mvc MVC KendoUI:如何禁用允许空值的NumericTextBox?,asp.net-mvc,model-view-controller,kendo-ui,kendonumerictextbox,Asp.net Mvc,Model View Controller,Kendo Ui,Kendonumerictextbox,我有一个KendoUI网格,允许用户使用内联模式更新值。问题是我有两个double属性不允许空值,但是NumericTextBox允许我设置一个空值,然后接受它,如下图所示: 如果按“Aceptar”(“Accept”)按钮,输入将保持为空,但它会将“0”保存在数据库中,并且只有在刷新页面时才能看到它。 这是网格的代码: @(Html.Kendo().Grid<ReferenceThresholdVM>() .Name("grdReference"
@(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“PositionEnumber”的代码:
有没有办法禁用让NumericTextBox为空的可能性?数值文本框上.Value的工具提示显示“设置文本框的初始值”。这就是为什么它要在数据库中保存0 根据我的评论,你实际上可能不得不做这样的事情
var numerictextbox = $("#numerictextbox").data("kendoNumericTextBox");
numerictextbox.value(0);
谢谢大家,伙计们!我通过在属性上使用“必需”装饰器来解决它
[Required] /*this is the important thing!*/
[Display(Name = "Umbral")]
[UIHint("PositiveNumber")]
public double? ntbThreshold
{
get;
set;
}
[Required]
[Display(Name = "Histeresis")]
[UIHint("PositiveNumber")]
public double? ntbHysteresis
{
get;
set;
}
现在,当您尝试设置一个空值时,它会显示一个验证错误。因此,如果您想在NumericTextBox上设置一个0,您必须编写它
问题不是在数据库中加载0,主要问题是在刷新页面之前,不会显示此0。请尝试为数字tb指定Id,然后在Jquery中执行此操作。
$(“#Id”).val(0)
应该在itI中抛出一个0,但我不能这样做,因为当您调用两个或多个具有相同id的元素时,Kendo有一个bug。正如您所看到的,我在UIHint上定义了模板,所以我不能使用.Name(“id”),因为它应该在div上调用具有相同id的两个元素。。。你明白了吗?无论如何谢谢你!是的,任何框架都不能有两个id。。。那就换个名字吧?视图中没有。将.HtmlAttributes(new{@class=“k-numerictextbox”})
更改为id。语法为@id=“w.e”或其just id=“w.e”,您应该立即接受自己的问题,以防止其显示为未解决问题。
var numerictextbox = $("#numerictextbox").data("kendoNumericTextBox");
numerictextbox.value(0);
[Required] /*this is the important thing!*/
[Display(Name = "Umbral")]
[UIHint("PositiveNumber")]
public double? ntbThreshold
{
get;
set;
}
[Required]
[Display(Name = "Histeresis")]
[UIHint("PositiveNumber")]
public double? ntbHysteresis
{
get;
set;
}