0

我在 MVC 4 中使用 radiobuttonfor,我试图为用户提供他可以选择的项目选择。My problem is when one of the items is selected and it's posted to the controller, the string value is a .net system.guid rather than the actual guid value.

  @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 />
  }

我有一个人员列表,其中包含他们的用户 ID。然后我希望用户选择一个单选按钮将该值绑定到模型。

-       list    Count = 3   System.Collections.Generic.List<System.Guid>
+       [0] {5fb7097c-335c-4d07-b4fd-000004e2d221}  System.Guid
+       [1] {5fb7097c-335c-4d07-b4fd-000004e2d222}  System.Guid
+       [2] {5fb7097c-335c-4d07-b4fd-000004e2d223}  System.Guid
+       Raw View        

当我发布它到这里:

 [HttpPost]
 public ActionResult SubmittedInterviews(InterviewManagement InterviewManagement)
 {
     return View();
 }

这是我在快速观看中可以看到的

-       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

没有说实际的 GUID。有任何想法吗?

4

1 回答 1

2

单选按钮通常用于我们希望用户只从提供的项目中选择一个选项的地方。

因此,您需要传递单个对象而不是列表:

foreach(var item in list)
{

    @Html.RadioButtonFor(m => m.InterviewSchedules[i].Chair, 
                         item.InterviewerID, 
                         new { @style = "width:auto;background:none;border:none" })
}
于 2014-05-12T09:20:31.980 回答