【问题标题】:Telerik Combobox not displaying binded valueTelerik Combobox 不显示绑定值
【发布时间】:2013-05-28 17:33:15
【问题描述】:

我在使用telerik 组合框时遇到困难,它显示一个空白值而不是模型的当前值。

我有以下型号:

    public decimal? ResourceId { get; set; }      
    public string ResourceName{ get; set; }        
    public decimal ResourceTypeId { get; set; }      
    public string ResourceTypeName{ get; set; }        

我希望我的视图在组合框中显示 ResourceTypeName 以便能够更改它,因此我将以下内容添加到我的模型中

    public IEnumerable<ResourceTypeModel> ResourceType()
    {
        ResourceTypeModel a = new ResourceTypeModel();

        a.ResourceTypeId = this.ResourceTypeId ;
        a.ResourceTypeName= this.ResourceTypeName;

        List<ResourceTypeModel> MyList= new List<ResourceTypeModel>();
        MyList.Add(a);

        return MyList;

    }

现在,我的视图包含以下组合框:

        @(Html.Telerik().ComboBoxFor(model => model.ResourceTypeId)
        .AutoFill(true)
        .DataBinding(binding => binding.Ajax().Select("_AutoCompleteAjaxLoadingResourceTypeList","ResourceController"))
        .BindTo(new SelectList(Model.ResourceType(), "ResourceTypeId", "ResourceTypeName"))                    
        .Filterable(filtering =>
        {
            filtering.FilterMode(AutoCompleteFilterMode.Contains);
            filtering.MinimumChars(2);
        })
        .HighlightFirstMatch(true)                    
        )

但是当我的视图打开时,组合框显示一个空值。

如果我单击组合框的下拉按钮,我想要显示的值就好像它是列表的第二项一样,我可以选择它。

组合框非常适合自动完成部分,并在键入时正确显示我所有可用的值,但根本不会直接显示所需的值。

【问题讨论】:

    标签: telerik-combobox


    【解决方案1】:

    所以,这是我的解决方案,它现在可以满足我的需求,但我仍然不明白为什么它不起作用。

    我修改了我的模型并从返回 ResourceType 列表的方法切换为 Ienumerable 属性,如下所示:

    public IEnumerable<ResourceTypeModel> ResourceType{ get; set; }
    

    我修改了我的模型构建器以使用我的 ResourceType 提供“单项列表” 并修改视图以在“.BindTo”中使用它

            @(Html.Telerik().ComboBoxFor(model => model.ResourceTypeId)
            .AutoFill(true)
            .DataBinding(binding => binding.Ajax().Select("_AutoCompleteAjaxLoadingResourceTypeList","ResourceController"))
            .BindTo(new SelectList(Model.ResourceType, "ResourceTypeId", "ResourceTypeName"))                    
            .Filterable(filtering =>
            {
                filtering.FilterMode(AutoCompleteFilterMode.Contains);
                filtering.MinimumChars(2);
            })
            .HighlightFirstMatch(true)                    
            )
    

    我一定是在某处做错了,因为我不明白为什么我需要修改模型并在其中添加一个列表以显示组合框内的当前值

    【讨论】:

      猜你喜欢
      • 2021-07-31
      • 2013-09-19
      • 2020-01-24
      • 1970-01-01
      • 2022-01-03
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多