我正在尝试更新旧的Web窗体应用程序以使用4.5中添加的新模型绑定功能,类似于MVC绑定功能.
我无法制作一个可编辑的FormView,它提供了一个包含简单成员的单个模型以及一个包含其他模型集合的成员.我需要用户能够编辑父对象的简单属性和子集合的属性.
问题是ProductChoice.Extras当代码尝试更新模型时,子collection()在模型绑定后始终为null.
这是我的模特:
[Serializable]
public class ProductChoice
{
public ProductChoice()
{
Extras = new List<ProductChoiceExtra>();
}
public int Quantity { get; set; }
public int ProductId { get; set; }
public List<ProductChoiceExtra> Extras { get; set; }
}
[Serializable]
public class ProductChoiceExtra
{
public int ExtraProductId { get; set; }
public string ExtraName { get; set; }
public int ExtraQuantity { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的用户控制代码背后:
public partial class ProductDetails : System.Web.UI.UserControl
{
private Models.ProductChoice _productChoice;
protected …Run Code Online (Sandbox Code Playgroud)