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.

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.