May 07, 2014, 2:00 PM
[CLOSED] [#484] Change code to solved that the CheckboxGroupFor doesn't auto checked when the property type is array
Hi!
I have a class which has a property LimitToSites, it type is List<Guid>, then i write some code in Cshtml like this
I have a class which has a property LimitToSites, it type is List<Guid>, then i write some code in Cshtml like this
Html.X().CheckboxGroupFor(p => p.SelectedSiteIds,
Model.AvailableSites.Select(p => new Checkbox.Config
{
BoxLabel = p.Name,
InputValue = p.Id.ToString()
})
)
I hope these checkboxes auto checked, but they wasn't. So, i read the file at Ext.Net.vs2013\Ext.Net\MVC\Extensions\WidgetExtens ions.cs, in row 425 i saw these code: List<string> values = new List<string>((model != null ? model.ToString().Split(',') : new string[0]));
And, i change the code like this:
List<string> values = new List<string>();
if (model != null)
{
if (model.GetType().IsArray)
{
foreach (var item in (model as Array))
{
values.Add(item.ToString());
}
}
else
{
values.AddRange((model != null ? model.ToString().Split(',') : new string[0]));
}
}
It's worked will! So, i hope the code will be add to the next version, thank you!
Last edited by Daniil; May 08, 2014 at 7:59 AM.
Reason: CLOSED]