This is a migrated thread and some comments may be shown as answers.

Html.Kendo().DropDownListFor() has nested collection model binding problem

3 Answers 157 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Eiji
Top achievements
Rank 1
Eiji asked on 09 May 2013, 07:03 AM
when nested collection model binding to Kendo DropDownList, 
not bind correctly .

Kendo.Mvc version is 2013.1.319.340

HomeControoler.cs
namespace MvcApplication5.Controllers
{
    public class ChildModel
    {
        public int CategoryId { get; set; }
    }
    public class ParentModel
    {
        public int CategoryId { get; set; }
        public ChildModel Child { get; set; }
        public List<ChildModel> Children { get; set; }
         
    }
 
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new ParentModel
            {
                CategoryId = 2,
                Child = new ChildModel { CategoryId = 2},
                Children = new List<ChildModel>
                {
                    new ChildModel { CategoryId = 2}
                }
            };
            return View(model);
        }
 
    }
}
Index.cshtml
@model MvcApplication5.Controllers.ParentModel
 
@{
    ViewBag.Title = "Index";
    var list = new List<SelectListItem>()
    {
      new SelectListItem() { Value = "1", Text = "one" },
      new SelectListItem() { Value = "2", Text = "two" },
      new SelectListItem() { Value = "3", Text = "three" },
    };
}
 
<h2>all actual categoryid must be 2</h2>
 
<h3>[OK] Model.CategoryId: @Model.CategoryId</h3>
@(Html.Kendo().DropDownListFor(m => m.CategoryId)
  .BindTo(list)
)
 
<h3>[OK] Model.CategoryId: @Model.Child.CategoryId</h3>
@(Html.Kendo().DropDownListFor(m => m.Child.CategoryId)
  .BindTo(list)
)
 
<h3>[NG] Model.Children[0].CategoryId: @Model.Children[0].CategoryId</h3>
@(Html.Kendo().DropDownListFor(m => m.Children[0].CategoryId)
  .BindTo(list)
)
<hr />
@Html.TextBoxFor(m => m.Children[0].CategoryId)
result

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 May 2013, 07:52 AM
Hello Eiji,

In some cases the value was overridden by the value from the SelectListItems in the official release. This problem is already fixed in the latest internal build(2013.1.509) that is available from your account. Please update the version you are using and let me know if you still experience this problem.

Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Eiji
Top achievements
Rank 1
answered on 14 May 2013, 05:36 AM
Hi Daniel.

I tried to only replace Kendo.Mvc.dll (
2013.1.319.340) with the new one( internal build, 2013.1.509) , 
all model binding worked corrrectly , thanks !

well, if I want to apply this patch production application, 
do I need to replace not only Kendo.Mvc.dll but also js, css and other resource ?

0
Daniel
Telerik team
answered on 15 May 2013, 03:41 PM
Hello again Eiji,

The fix was in the MVC wrapper so just replacing the assembly should resolve the problem and updating the CSS and JavaScript files should not be needed in this case. 

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Eiji
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Eiji
Top achievements
Rank 1
Share this question
or