I have two simple classes:
public class UserVM
{
public IList<UserRoleVM> PreselectedUserRoles { get; set; }
public IList<UserRoleVM> AllUserRoles { get; set; }
}
public class UserRoleVM
{
public int Id {get; set;}
public string Name {get; set;}
public bool IsSelected {get; set;}
}
Year, i implement two ways to pass preselected items, but only because none of them works.
After that i calls:
@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
user => user.AllUserRoles,
x => x.Id,
x => x.Name,
ur => ur.IsSelected, // error here
new { @class = "user-roles" })
And got error
CS1061: 'UserVM' does not contain a definition for 'IsSelected' and no extension method 'IsSelected' accepting a first argument of type 'UserVM' could be found (are you missing a using directive or an assembly reference?)
OK, i try:
@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
user => user.AllUserRoles,
x => x.Id,
x => x.Name,
user => user.PreselectedUserRoles, // error here
new { @class = "user-roles" })
CS1061: 'UserRoleVM' does not contain a definition for 'PreselectedUserRoles' and no extension method 'PreselectedUserRoles' accepting a first argument of type 'UserRoleVM' could be found (are you missing a using directive or an assembly reference?)
But when i get rid of 6th param width custom HTML code - all works fine.
// OK
@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
user => user.AllUserRoles,
x => x.Id,
x => x.Name,
user => user.PreselectedUserRoles
// OK
@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
user => user.AllUserRoles,
x => x.Id,
x => x.Name,
ur => ur.IsSelected)
How can i use custom html tags with MvcCheckBoxList?
I have two simple classes:
Year, i implement two ways to pass preselected items, but only because none of them works.
After that i calls:
And got error
OK, i try:
But when i get rid of 6th param width custom HTML code - all works fine.
How can i use custom html tags with MvcCheckBoxList?