문제

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?

도움이 되었습니까?

해결책

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" })

다른 팁

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")

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" })
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top