ASP.NET MVC CheckBoxList from model with List Property

No need to go away from Razor at all.

This works for me:

for (var i = 0; i < Model.UserRoles.Count(); i++)
{
    var role = Model.UserRoles[i];
    @Html.HiddenFor(model => model.UserRoles[i].RoleId)
    @Html.CheckBoxFor(model => model.UserRoles[i].Selected)
    @Html.LabelFor(model=> model.UserRoles[i].Name, role.Name)
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)