Default model binder and complex types that include a list

后端 未结 2 879
南方客
南方客 2020-12-09 06:42

I\'m using RC1 of ASP.NET MVC.

I\'m trying to extend Phil Haack\'s model binding example. I\'m trying to use the default model binder to bind the following object:

2条回答
  •  一生所求
    2020-12-09 07:25

    To answer my own question:

    I'm a dummy!

    My example doesn't work because the Items property of the ListOfProducts class is not public:

    public class ListOfProducts
    {
        public int Id { get; set; }
        public string Title{ get; set; }
        List Items { get; set; }
    }
    

    I changed:

    List Items { get; set; } 
    

    to:

    public List Items { get; set; }
    

    and my code then worked.

    To conclude the default model binder does work with types that contain properties of type List.

提交回复
热议问题