MVC RadioButtonFor组 [英] MVC RadioButtonFor group
本文介绍了MVC RadioButtonFor组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于PDF的课程
I have a class for a PDF
public class UIClonePDFDetail
{
public int CatalogueID { get; set; }
public List<PDF> PDFToClone { get; set; }
}
pdf类为:
public class PDF
{
public int ID{ get; set; }
public bool Selected{ get; set; }
}
我试图创建一个单选按钮列表供用户选择1,这将在PDFToClone列表的PDF元素上设置选定的属性.
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")
但这允许选择多个单选按钮.我可以理解为什么会这样,因为Html标记的名称元素不同.有没有办法强迫他们进入同一个家庭?
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" })
这篇关于MVC RadioButtonFor组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文