1

I'm new to asp.net mvc 4 and I'm stuck at displaying radiobuttons for the items in my model. I'm using asp.net identity 2 for user authentication and roles assignments. I want to display the roles as radio buttons so that the admin has the option to set the role for each user. The radio button appears but on clicking the save/submit button the role of the user is not saved in the database.

Below is my view:

          <div class="form-group">
        @Html.Label("Roles", new { @class = "control-label col-md-2" })
        <span class=" col-md-10">
            @foreach (var item in Model.RolesList)
            {

             @Html.RadioButtonFor(m => m.RolesList, new { @class = "radio-inline",id="role"+item.Value})

                @Html.Label(item.Value, new { @class = "control-label" })
            }


        </span>
    </div>

Please guide me through this. Thank you. I have also attached an image of how it appears.I don't understand why there's X and Y appearing next to the label.

Screenshot of my view

trailmax
  • 34,305
  • 22
  • 140
  • 234
newbie
  • 173
  • 4
  • 21
  • Will also be a good idea to show your model and controller code, but have a read here: http://stackoverflow.com/questions/5768274/correct-way-to-bind-an-mvc3-radiobutton-to-a-model for a very good example of radio buttons in MVC – Henry24 Oct 04 '16 at 19:28
  • Property `RolesList` is a collection and you cannot bind a radio button to a collection. And you have said you want to assign _roles_ (plural) and a radio button group only allows you to assign one role - you need checkboxes to assign multiple roles to a user. Refer [this answer](http://stackoverflow.com/questions/29542107/pass-list-of-checkboxes-into-view-and-pull-out-ienumerable/29554416#29554416) for a typical implementation. –  Oct 04 '16 at 22:33

0 Answers0