私はこれを少し調べましたが、同様の状況またはMVC3を完全に扱う答えは見つかりませんでした。私が使用しているViewModelには、別List<AgentId>
のモデルのリスト(モデルのリストAgentId
)があります。
このコントローラーのCreate
ページで、このリストに追加する5つのアイテムの入力セクションが必要です。ただし、ページが読み込まれる前に、次のエラーメッセージが表示されます。
There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'BankListAgentId[0].StateCode'.
これが私が使用しているViewModelです:
public class BankListViewModel
{
public int ID { get; set; }
public string ContentTypeID1 { get; set; }
public string CreatedBy { get; set; }
public string MANonresBizNY { get; set; }
public string LastChangeOperator { get; set; }
public Nullable<System.DateTime> LastChangeDate { get; set; }
public List<BankListAgentId> BankListAgentId { get; set; }
public List<BankListStateCode> BankListStateCode { get; set; }
}
そして、これが問題を抱えているビューのセクションです:
<fieldset>
<legend>Stat(s) Fixed</legend>
<table>
<th>State Code</th>
<th>Agent ID</th>
<th></th>
<tr>
<td>
@Html.DropDownListFor(model => model.BankListAgentId[0].StateCode,
(SelectList)ViewBag.StateCode, " ")
</td>
<td>
@Html.EditorFor(model => model.BankListAgentId[0].AgentId)
@Html.ValidationMessageFor(model => model.BankListAgentId[0].AgentId)
</td>
</tr>
<tr>
<td>
@Html.DropDownListFor(model => model.BankListAgentId[1].StateCode,
(SelectList)ViewBag.StateCode, " ")
</td>
<td>
@Html.EditorFor(model => model.BankListAgentId[1].AgentId)
@Html.ValidationMessageFor(model => model.BankListAgentId[1].AgentId)
</td>
<td id="plus2" class="more" onclick="MoreCompanies('3');">+</td>
</tr>
</table>
</fieldset>