Kendo combobox not show the Text corresponding to value from modal

2k views Asked by At

I have a partial view with a combobox. When try to render partial view with modal(contains data from database), it shows only the value field. i want to show the text field of that value field. Help me please.

@(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");
        });
    })
)
3

There are 3 answers

0
RajeshKdev On

There is no fault i found with your view code. Its just looks fine to me. I think you are doing same as this sample.

I suspect your value assignment to c.divisioncode, Name = c.divisionname. Just make sure you are getting and setting value and text properly From your db service calls to view model and assigning correctly. For that you can use and see the "quick watch" while debugging the GetDivision "Action" in AssetTransaction "controller".

Sample Code i found:

@(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);
          })
    )
0
irgnosis On

I was facing similar issue since my model has attribute for code.

I changed

AutoBind(false) 

to

AutoBind(true). 

Now it shows the Text instead of the Value

0
Tawab Wakil On

You can set AutoBind to false (which you've already done), and then use the Text property to define the text that will be displayed:

@(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");
    });
})