Skip to content

Overload function choice problem #17

@lansman

Description

@lansman

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions