DropdownList Model Binding - Unable to get it working

2 posts, 1 answers
  1. Uday
    Uday avatar
    17 posts
    Member since:
    Jun 2014

    Posted 04 Aug 2014 Link to this post

    Hi everyone,

    I am having hard time getting the model binding work with the DropdownList.

    * I am not manually setting the name on the widget
    * I do not have AutoBind set to false 

    @(Html.Kendo().DropDownListFor(m=> m.SelectedProduct)
              .HtmlAttributes(new { style = "width: 250px" })
              .DataSource(source =>
                  source.Read(read =>
                      read.Action("GetProducts", "DropdownList");

    This is from the telerik demos.

    Here is the Controller Code:
    public ActionResult RemoteDataSource()
               var model = new RemoteDataSourceViewModel()
                   SelectedProduct = new SelectedProduct()
                       ProductID = 7,
                       ProductName = "Uncle Bob's Organic Dried Pears"
               return View(model);

    The above code would load the dropdownlist, but doesn't set the value on initial load.

    I looked through previous post and could not find why this wouldn't work.

    Any suggestions on what I might be doing wrong?

    I appreciate your time.

  2. Answer
    Alexander Popov
    Alexander Popov avatar
    1436 posts

    Posted 06 Aug 2014 Link to this post

    Hi Uday,

    This happens because the DropDownList's value should be an integer matching the ProductID. Using the ProductID property (instead of a complex object) as an argument for the DropDownListFor helper should do the trick. 

    Alexander Popov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top