Kendo组合框不显示对应于模态值的Text

本文关键字:模态 Text 于模态 组合 显示 Kendo | 更新日期: 2023-09-27 17:59:28

我有一个带有组合框的局部视图。当尝试使用模态(包含数据库中的数据)呈现局部视图时,它只显示值字段。我想显示该值字段的文本字段。请帮帮我。

@(Html.Kendo().ComboBoxFor(m => m.divCode)
    .DataTextField("Name")
    .DataValueField("ID")                                        
    .HtmlAttributes(new { style = "width:160px" })
    .SelectedIndex(0)
    .AutoBind(false)
    .Placeholder("Select Div Code")
    .Filter(FilterType.Contains)
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetDivision", "AssetTransaction");
        });
    })
)

Kendo组合框不显示对应于模态值的Text

我没有发现您的视图代码有任何错误。我觉得很好。我想你们做的和这个样品一样。

我怀疑你对c.divisioncode, Name = c.divisionname的价值分配。只需确保您正确地获取和设置了value and text。从您的数据库服务调用中可以正确地查看模型和分配。为此,您可以使用并查看"快速观察"while debugging the GetDivision "Action" in AssetTransaction "controller"

我找到的示例代码:

@(Html.Kendo().ComboBox()
          .Name("products")
          .DataTextField("ProductName")
          .DataValueField("ProductID")
          .HtmlAttributes(new { style = "width:250px" })
          .Filter("contains")
          .AutoBind(false)
          .MinLength(3)
          .DataSource(source => {
              source.Read(read =>
              {
                  read.Action("GetProducts", "Home");
              })
              .ServerFiltering(true);
          })
    )

我遇到了类似的问题,因为我的模型有代码的属性。

我更改了

AutoBind(false) 

AutoBind(true). 

现在它显示的是Text而不是Value

您可以将AutoBind设置为false(您已经这样做了),然后使用Text属性定义将显示的文本:

@(Html.Kendo().ComboBoxFor(m => m.divCode)
.DataTextField("Name")
.DataValueField("ID")                                        
.HtmlAttributes(new { style = "width:160px" })
.SelectedIndex(0)
.AutoBind(false)
.Text(Model.YourTextFieldToDisplay)  // add this and modify to your needs
.Placeholder("Select Div Code")
.Filter(FilterType.Contains)
.DataSource(source =>
{
    source.Read(read =>
    {
        read.Action("GetDivision", "AssetTransaction");
    });
})