モデルバインディングを使用してMVCのように子コレクションを更新する方法を理解できません。すべてのコレクション型のコントロールは、編集/更新のライフサイクルを使用するサーバー側の記憶域メカニズムを想定しているようですが、これは、フォームの中に子コレクションを格納する挿入フォームであると思われる場合は適合しません。Webフォームモデルバインディング子コレクション
public class BarViewModel
{
public string Name {get;set;}
}
public class FooViewModel
{
public string Description {get;set;}
public List<BarViewModel> Bars {get;set;}
}
ここでは何が使えますか?ここにセクション:
<asp:FormView ID="Entry" RenderOuterTable="false" runat="server" DefaultMode="Insert"
ItemType="FooViewModel" SelectMethod="Entry_GetItem" InsertMethod="Entry_InsertItem">
<InsertItemTemplate>
<asp:TextBox ID="txtDescription" Text="<%# BindItem.Description %>" runat="server" />
<!-- ??? -->
</InsertItemTemplate>
</asp:FormView>
私はTryUpdateModelを実行InsertMethodを書くことができ、子コレクションはからの値で移入するようにするには?
リピータ、グリッドビュー、リストビューを試しましたが、どれも動作していないようです。この問題は、オンライン[1]の回答はないようですが、明白なシナリオでなければならないようで、MVCでは簡単です。
[1]私は見つけることができるASP.NET Web Forms 4.5 model binding where the model contains a collection