1

我有这个模型:

 public class ReservationViewModel
 {        
  public Flight InboundFlight { get; set; }
  public Flight OutboundFlight { get; set; }
 }

 //Flight
 public class Flight
 {
  public List<ISeat> Seats { get; set; }
 }

 //Seats
  public interface ISeat 
  {
    ECabin Cabin { get; }
    int NumberOfSeatsAvailable { get; }
    int SeatsChosen { get; set; }
    string PropertyName { get; }
 }

我的 HTML 包含以下内容:

<select id="OutboundFlight__0__Seats_SeatsChosen" name="OutboundFlight.[0].Seats.SeatsChosen" class="valid"><option...
<select id="OutboundFlight__0__Seats_SeatsChosen" name="OutboundFlight.[1].Seats.SeatsChosen" class="valid"><option...
<select id="OutboundFlight__0__Seats_SeatsChosen" name="OutboundFlight.[2].Seats.SeatsChosen" class="valid"><option...

我的行动:

    [HttpPost]
    public ActionResult Index(ReservationViewModel model, FormCollection form)
    {            
        return View();
    }

提交后,我尝试绑定回模型,但每个航班的座位返回 null... 帮助将不胜感激

4

1 回答 1

1

生成的 HTML 不正确,无法将其绑定到列表 - 字段名称必须与从 c# 访问属性的内容相匹配:

这应该有效:

name="OutboundFlight.Seats[0].SeatsChosen"
于 2012-05-02T16:35:48.617 回答