this posterのように、私はASP.NET MVC Html.ListBoxFor(...)とちょっと混乱しています。具体的に私は、リスト内の選択結果を入れているが、私は結果を投稿した後、私はここでASP.NET MVC Html.ListBoxFor(...)SelectExtensionで混乱しています
InvalidOperationException: The ViewData item that has the key 'SelectedDeclarations' is of type 'System.String[]' but must be of type 'IEnumerable<SelectListItem>'
を取得しています、私は強く型付けされたかみそりビュー
public MyViewModel
{
public MyViewModel()
{
(...)
this.VendorsRequiringDeclaration = new List<SelectListItem>();
this.SelectedDeclarations = new List<String>();
}
public IEnumerable<String> SelectedDeclarations { get; set; }
public List<SelectListItem> VendorsRequiringDeclaration { get; set; }
}
に渡している私の省略のViewModelです
、ここでは、私はSelectedDeclarationsはポストtの時、SelectedListItemの一覧ではなく、文字列のリストであるようなMyViewModelを変更した場合は、それらを
@Html.ListBoxFor(m=>m.SelectedDeclarations, Model.VendorsRequiringDeclaration, new { @class="editor-field", @size=6})
を参照するビューコードですo私のモデルが無効であると思う適切なコントローラーのアクション:
アイデア?私はおそらく最初のパラメータに間違ったLINQの表現を持っていますが、私は同様の質問からそれを見ることはできません。前もって感謝します!
は、それが役立つかもしれない、この質問について見てみましょう: 私は以下のようなものをHtml.ListBoxFor(...)をリワークなかった、正常に動作するようですけれどもAlexanderBの提案に基づいて
http://stackoverflow.com/questions/2308846/why-is-listboxfor-not-selecting-items-but-listbox-is –