How to bind initial value for ComboBox with server filtering?

2 posts, 0 answers
  1. StefanDV
    StefanDV avatar
    1 posts
    Member since:
    Nov 2012

    Posted 25 Jul Link to this post

    Hi

     

    I am using databinding in my MVC view with ComboBoxFor (see sample below).

    This works great when I am using this the first time (new record). However, when I want to Edit my entity, I want that upon opening the view, the ProductName is already there. How to accomplish this? If I set the .Text property then this is showed, but the binding gets lost when I save. Is there a way set force a call to the controller to get the ProductName based upon the bound MyProductId?

     

    @(Html.Kendo().ComboBoxFor(m => m.MyProductID)
              .Placeholder("Select product")
              .DataTextField("ProductName")
              .DataValueField("ProductID")
              .HtmlAttributes(new { style = "width:100%;" })
              .Filter("contains")
              .AutoBind(false)
              .MinLength(3)
              .DataSource(source => {
                  source.Read(read =>
                  {
                      read.Action("GetProducts", "Home");
                  })
                  .ServerFiltering(true);
              })
        )

  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 27 Jul Link to this post

    Hello Stefan,

    Since you mentioned new records and editing I guess the combobox is integrated as an editor template inside a databound control (e.g., a grid). If that is the case you can examine the samples below which illustrate similar approaches:

        - Grid editing using ComboBox with remote binding and filtering
        - Using Cascading DropDownLists as custom editors for Grid InCell edit mode
        - Grid to handle cascading dropdownlists with popup or inline editing mode
       -  Grid / ForeignKey column

    Regards,
    Danail Vasilev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top