0

こんにちは、私は次のビューモデルを持っています:

public class VehiclesViewModel
    {
        public IList<Vehicle> Vehicles{ get; set; }
    }

車両は:

public class Vehicle
{
  public Owner Owner { get; set; }
  public Make Make { get; set; }
  public string Status { get; set; }
}

カミソリビューで:

    @model VehiclesViewModel

    <table>
      <thead>
        <tr>
          <th>Owner</th>
          <th>Make</th>
          <th>Model</th>
        </tr>
      </thead>
      <tbody>
    @for(int i=0; i<Model.Vehicles.Count; i++)
    {

        <tr>
          <td>@Vehicle[i].Owner</td>
          <td>@Vehicle[i].Make</td>
          <td>@Html.EditorFor(x => x.Vehicles[i].Status)</td>
        </tr>

    }
    </tbody>
</table>

これで、車両のステータスを表示および変更し、問題なくコントローラにポストできるビューができました。

ただし、車両の所有者によってグループ化されたページに車両を表示するという新しい要件があります。だから私は思いついた:

@model VehiclesViewModel

<table>
  <thead>
    <tr>
      <th>Make</th>
      <th>Model</th>
    </tr>
  </thead>
  <tbody>
@foreach(var vehicleGroup in @Model.Vehicles.GroupBy(x => x.Owner.Name))
{
  <tr>
     <td colspan="2">@vehicleGroup.First().Owner.Name</td>
  </tr>
  foreach(var vehicle in vehicleGroup)
  {

       <tr>
         <td>@vehicle.Make.Name</td>
         <td>Need to provide a way to edit the status here</td>
       </tr>

  }
}
</tbody>
</table>

問題は、ステータスの書き方や編集方法がわかりません。

誰でもこれで私を助けることができますか?

4

2 に答える 2

0

単純な入力タグを使用するだけかもしれません:

<input type="text" name="vehicle-@vehicle.Id"value="@vehicle.Status" />
于 2013-05-13T23:40:13.503 に答える