Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload function choice problem #17

Open
lansman opened this issue Sep 9, 2016 · 1 comment
Open

Overload function choice problem #17

lansman opened this issue Sep 9, 2016 · 1 comment

Comments

@lansman
Copy link

lansman commented Sep 9, 2016

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?

@mikhail-tsennykh
Copy link
Owner

mikhail-tsennykh commented Sep 29, 2016

Sorry for the late reply, I'll post it here in case someone else has the same issue.

Unfortunately, those overload parameters have a different meaning depending on number parameters used. I believe custom html tags would only work using full example:

var htmlListInfo = new HtmlListInfo(HtmlTag.vertical_columns, 2, new { @class="styled_list" };
@Html.CheckBoxListFor(x => x.PostedCities.CityIDs,
                      x => x.AvailableCities,
                      x => x.Id,
                      x => x.Name,
                      x => x.SelectedCities,
                      new { @class="styled_checkbox" },      // additional html attributes (for each checkbox and label)
                      htmlListInfo),                         // formatting
                      new[] {"3", "5", "7"},                 // disabled values
                      x => x.Tags)                           // html tags from database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants