发布到控制器MVC asp.net后列表为空

时间:2016-10-19 11:36:18

标签: c# asp.net-mvc list model-view-controller dropdownlistfor

我发给控制器的列表是空的。虽然它在httpGet请求中显示数据。 我的控制器是

 public ActionResult viewOrder(IList<Order> list)

我的ViewFile是

     @using (Html.BeginForm("viewOrder", "Tables", FormMethod.Post))
    {
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                      <th>Order ID</th>
                      <th>Assign Driver</th>
                      <th>Status</th>
                      <th>Cost</th>

                    </tr>
                    </thead>
                      <tbody>
                          @foreach (var x in Model)
                          {
                              <tr>
                                  <td><a href="#">@x.OrderId</a></td>
                                  <td>
                                      @Html.DropDownListFor(model => model.Where(q => q.OrderId == x.OrderId).First().DriverId, new SelectList(driver, "DriverId", "FirstName", driver.First().DriverId))
                                  </td>

        </tr>
}
   <button type="submit" class="btn btn-primary">Update</button>
}

我的模特是

 public partial class Order
    {
        public int OrderId { get; set; }
        public string Name { get; set; }
        public Nullable<int> TeamId { get; set; }

        public Nullable<int> Price { get; set; }
        public Nullable<int> SalespersonId { get; set; }
        public Nullable<int> TotalCost { get; set; }
        public Nullable<int> OrderId { get; set; }


        public virtual Salesman Salesman { get; set; }
        public virtual Team Team { get; set; }
        public virtual Driver Driver { get; set; }
    }

当我点击提交按钮时。它运行成功,但在我的控制器中出错,列表为空。我搜索了相同的语法,但我的代码没有运行

0 个答案:

没有答案