mikhail-tsennykh/MvcCheckBoxList — pull request #7 by RobRolls (2013-12-20 06:59:58+00:00)
Title: Fix for malformed id in nested edit templates

I had a scenario where I was calling @Html.EditorFor() on a collection of items that each end up rendering as their own EditorTemplate. For instance I have a the following:
```
public class SomeFolksViewModel
{
public string State {get; set;}
public IList People {get; set;}
}

public class Person
{
public string Name {get; set;}
public IList TeethQuantityAvailable { get; set; }
public IList TeethQuantitySelected { get; set; }
public PostedTeethQuantity PostedTeethQuantitys { get; set; }
}

public class PostedTeethQuantity
{
public string[] TeethQuantitys { get; set; }
}

// SomeFolksView.chstml
@model SomeFolksViewModel

@Html.LabelFor(m => m.State)
@Html.TextBoxFor(m => m.State, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.State)

@Html.EditorFor(m => m.People)

// EditorTemplate/Person.cshtml
@model Person

@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Name)

@Html.CheckBoxListFor(model => model.PostedTeethQuantitys.TeethQuantitys,
model => model.TeethQuantityAvailable,
entity => entity.Name,
entity => entity.Name,
model => model.TeethQuantitySelected, Position.Vertical)

```
say I create the ViewModel and load 2 Person into the People collection. I add 3 entries to TeethQuantityAvailablecollection "All","Some","None".

ok, I run this and I end up with rendered CBL but the id's are wrong.

I end up with something like this (i've ommited labels, etc.) for person 1
```
All
Some
None
```
and this for person 2
```
All
Some
None
```
This does not work. The Id's are malformed, they are missing their parent object name. When the page is posted back the ID's don't properly map back to the viewmodel and I end up with a lot of extra People in my list.

To make it work the cbl Ids should look like the following

Person 1:
```
All
Some
None
```
Person 2:
```
All
Some
None
```