Asp.net mvc 4 使用带有MVC RadioButton的列表
我在MVC4中使用RadioButtonOn,我试图为用户提供可以选择的项目。我的问题是,当选择其中一项并将其发布到控制器时,字符串值是.net system.guid,而不是实际的guid值Asp.net mvc 4 使用带有MVC RadioButton的列表,asp.net-mvc-4,razor,model,radiobuttonfor,Asp.net Mvc 4,Razor,Model,Radiobuttonfor,我在MVC4中使用RadioButtonOn,我试图为用户提供可以选择的项目。我的问题是,当选择其中一项并将其发布到控制器时,字符串值是.net system.guid,而不是实际的guid值 @foreach (var person in Model.InterviewDates[i].Interviewers) // all interviewers - not filtered { var list = Model.InterviewDates[i].Intervie
@foreach (var person in Model.InterviewDates[i].Interviewers) // all interviewers - not filtered
{
var list = Model.InterviewDates[i].Interviewers.Select(p => p.InterviewerID).ToList();
@Html.Raw(person.InterviewerName + " ")
// TODO: Lambda for getting all Chairs based on interview type and interview date
@Html.RadioButtonFor(m => m.InterviewSchedules[i].Chair, list, new { @style = "width:auto;background:none;border:none" })
<br />
}
这是我在快速观察中看到的
- InterviewManagement {IMecheAdmin.Models.InterviewManagement} IMecheAdmin.Models.InterviewManagement
+ InterviewDates Count = 0 System.Collections.Generic.List<IMecheAdmin.Models.InterviewDate>
- InterviewSchedules Count = 1 System.Collections.Generic.List<IMecheAdmin.Models.InterviewSchedule>
- [0] {IMecheAdmin.Models.InterviewSchedule} IMecheAdmin.Models.InterviewSchedule
Chair "System.Collections.Generic.List`1[System.Guid]" string
Cofacilitator null string
Facilitator null string
+ InterviewDate {01/01/0001 00:00:00} System.DateTime
Location null string
Observer null string
Preference false bool
Site null string
+ Raw View
+ InterviewTypes Count = 0 System.Collections.Generic.List<IMecheAdmin.Models.InterviewType>
SelectedMembershipType null string
没有说实际的GUID。有什么想法吗?单选按钮通常用于我们希望用户只从提供的项目中选择一个选项的地方 因此,您需要传递单个对象,而不是列表:
foreach(var item in list)
{
@Html.RadioButtonFor(m => m.InterviewSchedules[i].Chair,
item.InterviewerID,
new { @style = "width:auto;background:none;border:none" })
}
谢谢Ehsan!出于某种原因,我认为它想要一个集合,但我已经通过foreach循环制作了多个收音机,所以我得到我只需要通过该项目。实际上,我在代码中使用了person,但这只是语义:)对于Radio按钮,对象是需要的,而不是列表,这是不可理解的,如果您想使用列表,您必须编写自己的自定义html帮助程序
- InterviewManagement {IMecheAdmin.Models.InterviewManagement} IMecheAdmin.Models.InterviewManagement
+ InterviewDates Count = 0 System.Collections.Generic.List<IMecheAdmin.Models.InterviewDate>
- InterviewSchedules Count = 1 System.Collections.Generic.List<IMecheAdmin.Models.InterviewSchedule>
- [0] {IMecheAdmin.Models.InterviewSchedule} IMecheAdmin.Models.InterviewSchedule
Chair "System.Collections.Generic.List`1[System.Guid]" string
Cofacilitator null string
Facilitator null string
+ InterviewDate {01/01/0001 00:00:00} System.DateTime
Location null string
Observer null string
Preference false bool
Site null string
+ Raw View
+ InterviewTypes Count = 0 System.Collections.Generic.List<IMecheAdmin.Models.InterviewType>
SelectedMembershipType null string
Chair "System.Collections.Generic.List`1[System.Guid]" string
foreach(var item in list)
{
@Html.RadioButtonFor(m => m.InterviewSchedules[i].Chair,
item.InterviewerID,
new { @style = "width:auto;background:none;border:none" })
}