0

I'm following this answer here, with this code:

SomeControl.cshtml

@model Econo.WebUI.ViewModel.UserRoleViewModel

@Html.HiddenFor(x => Model.UserId)

@Html.EditorFor(x => Model.Roles)

/Shared/EditorTemplates/Roles.cshtml

@model Econo.WebUI.ViewModel.RoleViewModel

@Html.EditorFor(m => m.IsInRole)
@Html.EditorFor(m => m.RoleId)
@Html.EditorFor(m => m.RoleName)

For some reason, this only output:

<input id="UserId" type="hidden" value="1LS82" name="UserId">
FalseFalse

The FalseFalse shows that there are 2 roles in the database and the user is in none of them, which is correct. But I need a checkbox with the ID and Name. Also being able to submit this back to the server to add roles to user.

Community
  • 1
  • 1
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406

1 Answers1

1

Your partial is wrongly named. It should be ~/Shared/EditorTemplates/RoleViewModel.cshtml and not ~/Shared/EditorTemplates/Roles.cshtml. And then:

@model Econo.WebUI.ViewModel.RoleViewModel

@Html.CheckBoxFor(m => m.IsInRole)
@Html.LabelFor(m => m.RoleName)
@Html.HiddenFor(m => m.RoleId)
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928