2

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");
        });
    })
)
Ajith
  • 343
  • 2
  • 23
  • What does `GetDivision()` return? –  Jun 25 '15 at 04:43
  • @ Stephen Muecke, modal with text field and value field, combobox works perfectly on selection. my issue is when try to edit form `return Json(divisionViewModel.Select(c => new { ID = c.divisioncode, Name = c.divisionname }) .OrderBy(o => o.ID) .ToList(), JsonRequestBehavior.AllowGet);` – Ajith Jun 25 '15 at 04:46
  • What is the issue? Are you getting any error with json statement? Have you observed response? – Priyank Sheth Jun 25 '15 at 05:12
  • simple Man, there is no errors. when i try to set combobox from database it shows the value not text, that was my issue, – Ajith Jun 25 '15 at 05:22

3 Answers3

1

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);
          })
    )
RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
1

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

zx485
  • 28,498
  • 28
  • 50
  • 59
irgnosis
  • 81
  • 1
  • 3
0

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");
    });
})
Tawab Wakil
  • 1,737
  • 18
  • 33