Reputation: 3111
I have a class for a PDF
public class UIClonePDFDetail
{
public int CatalogueID { get; set; }
public List<PDF> PDFToClone { get; set; }
}
The pdf class is:
public class PDF
{
public int ID{ get; set; }
public bool Selected{ get; set; }
}
I am trying to create a list of radiobuttons for the user to select 1 and this sets the selected property on the PDF element in the PDFToClone list.
Html.RadioButtonFor(model => Model.UIClonePDFDetail[Model.UIClonePDFDetail.IndexOf(stageSelection)].Selected, "stageSelection")
But this allows nultiple selection of radio buttons. I can see why this is happening, because the name elements of the Html tags are different. Is there a way of forcing them into the same family?
Upvotes: 3
Views: 13158
Reputation: 536
You could try to pass htmlAttributes with the group of the radiobutton, with something like:
@Html.RadioButtonFor(model => Model.UIClonePDFDetail[Model.UIClonePDFDetail
.IndexOfstageSelection)].Selected, "stageSelection", new { Group = "A" })
Upvotes: 0
Reputation: 6026
RadioButtonFor contains an overload that accepts HTML attributes. You can create an anonymous type and include the Name attribute like this:
Html.RadioButtonFor(model => Model.UIClonePDFDetail[Model.UIClonePDFDetail
.IndexOfstageSelection)].Selected, "stageSelection", new { Name = "grp" })
Upvotes: 8
Reputation: 5093
Please try to use:
Html.RadioButtonFor(model =>
Model.UIClonePDFDetail[Model.UIClonePDFDetail.IndexOf(stageSelection)].Selected,
"stageSelection")
instead of:
Html.CheckBoxFor(model =>
Model.UIClonePDFDetail[Model.UIClonePDFDetail.IndexOf(stageSelection)].Selected,
"stageSelection")
Upvotes: 0