I am having trouble with ASP.NET WebForm (not MVC) model binding.
For example, if you want to edit the following classes using FormView with bidirectional model bindings,
public class Lover{
public class name {get;set;}
public age {get;set;}
}
public class Employee {
public string name {get;set;}
public string address {get;set;}
public List<Lover>lovers {get;set;}
}
For models such as ,
Name<asp:textbox id="name" runat="server"text="<%#BindItem.name%>"/gt;
Address <asp:textbox id="address" runat="server"text="<%#BindItem.address%>"
Lover 1 Name <asp:textbox id="lovers[0].name" runat="server" text="<%#BindItem.lovers[0].name%>"
Lovers 1 age <asp:textbox id="lovers[0].age" runat="server" text="<%#BindItem.lovers[1].age%>"
If so, an error will appear.
Both the id name and the BindItem seemed impossible to specify array elements.
ASP.NET MVC is fine.
How can I do model binding on Web Form?
asp.net
You cannot bind directly to the IList
element.Consider adding properties such as Lover1, Lover2, Lover3, etc. on the model side or using <asp:Repeater>
etc.
The ID
attribute does not need to be matched with the data bind expression, so you can specify an appropriate name such as lovers_0__name
.
© 2024 OneMinuteCode. All rights reserved.