Kendo ui Kendo DropdownlistFor nullable bool未设置null值
为什么会发生这种情况?试试Kendo ui Kendo DropdownlistFor nullable bool未设置null值,kendo-ui,nullable,dropdownlistfor,Kendo Ui,Nullable,Dropdownlistfor,为什么会发生这种情况?试试选项标签属性,它对我有用 [DisplayName("Autostart Load")] public bool? AutoStartLoad { get; set; } @Html.Kendo().DropDownListFor(model=>model.SomeProperty).OptionLabel(“选择值…”).BindTo(新列表()) { 新建SelectListItem(){Text=“Yes”,Value=“True”}, 新建SelectList
选项标签
属性,它对我有用
[DisplayName("Autostart Load")]
public bool? AutoStartLoad { get; set; }
@Html.Kendo().DropDownListFor(model=>model.SomeProperty).OptionLabel(“选择值…”).BindTo(新列表())
{
新建SelectListItem(){Text=“Yes”,Value=“True”},
新建SelectListItem(){Text=“No”,Value=“False”},
});
公共场所?SomeProperty{get;set;}
同时设置true
和false
的值,以大写字母开头,因为bool.ToString()
将值返回为“true”
和“false”
请尝试以下操作:
@Html.Kendo().DropDownListFor(model => model.SomeProperty).OptionLabel("Choose value...").BindTo(new List<SelectListItem>()
{
new SelectListItem() { Text = "Yes", Value = "True" },
new SelectListItem() { Text = "No", Value = "False" },
});
public bool? SomeProperty { get; set; }
@Html.Kendo().DropDownListFor(model=>model.SomeProperty).BindTo(新列表()
{
新建SelectListItem(){Text=“Choose value…”,value=“null”},
新建SelectListItem(){Text=“Yes”,Value=“True”},
新建SelectListItem(){Text=“No”,Value=“False”},
});
这不是剑道控制特有的问题。我们有一个类似的问题,自定义3状态选项按钮组。除非将空值作为字符串发布,否则不会发布它们
在原始代码中,只需在引号中加null。这应该可以解决问题。这是剑道格网吗?你真的测试过吗?“它不仅不起作用,而且当我把真假大写时,它甚至更坏了。”@JohnLord答案是5岁。从那以后可能发生了很多变化。除了bool.ToString()在绑定到模型并且控件呈现现有模型值时仍能很好地利用它之外,它显然没有在内部进行字符串比较。我不知道这是否改变了,但它没有资本化,也没有资本化。很抱歉,我不确定:)我不记得了,但我认为它在过去对我有效
@Html.Kendo().DropDownListFor(model => model.SomeProperty).OptionLabel("Choose value...").BindTo(new List<SelectListItem>()
{
new SelectListItem() { Text = "Yes", Value = "True" },
new SelectListItem() { Text = "No", Value = "False" },
});
public bool? SomeProperty { get; set; }
@Html.Kendo().DropDownListFor(model => model.SomeProperty).BindTo(new List<SelectListItem>()
{
new SelectListItem() { Text = "Choose value...", Value = "null" },
new SelectListItem() { Text = "Yes", Value = "True" },
new SelectListItem() { Text = "No", Value = "False" },
});