In my application I want to enable the user to add other users to a single role.
Therefore my model contains a IDictionary<string, IEnumerable<string>>
where the key is the name of the role and value is the list of user-names that will be set to the given role.
However, I'm struggling on how to post this (or event how to create the hidden fields in my form) so I can access the dictionary inside my action.
This article seem to address an related issue but I did not get it managed to post the correct data.
Currently my code looks something like this:
foreach (var roleToUserRelation in Model.RoleUserRelations)
{
@Html.Hidden(Html.NameFor(m => m.RoleUserRelations) + ".Index", s)
@Html.HiddenFor(m => m.RoleUserRelations[s]);
// loop through each user
foreach (var userName in roleToUserRelation.Value)
{
// get the list somehow rendered to be posted as value for the dictionary
@Html.Hidden(m => userName)
}
}
Is it possible to do it this way or should I re-think the model-structure in order to avoid the usage of a dictionary here?