Default model binder and complex types that include a list

后端 未结 2 873
南方客
南方客 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<Product> Items { get; set; }
    }
    

    I changed:

    List<Product> Items { get; set; } 
    

    to:

    public List<Product> Items { get; set; }
    

    and my code then worked.

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

    0 讨论(0)
  • 2020-12-09 07:39

    Starting with RC 1:

    • Hidden Index is no longer required
    • The number in [] must start with 0 and must ascend.

    Your numbering looks OK.

    Also, I noticed that you used different casing on your items property name. That should not make a difference, but it's worth checking.

    0 讨论(0)
提交回复
热议问题