ASP.NET MVC model binding an IList<> parameter

前端 未结 1 2010
北恋
北恋 2020-12-05 07:31

[I solved this myself, see my answer for cause]

I\'m having trouble getting form values for a IList<> argument in a controller method set properl

相关标签:
1条回答
  • 2020-12-05 07:55

    Solution

    After downloading the MVC source I still couldn't see why it wouldn't work, so I presumed it must be something to do with the type I was attempting to bind. Sure enough, the values being member variables, as opposed to properties, was the culprit. This is because the model binder uses reflection to set properties, which it wasn't finding through the call to TypeDescriptor.GetProperties(Type).

    Updating the value class to this solved it (after hours of hitting head off wall I should add!!):

    public class ShoppingBasketItem {
        public int ItemID { get; set; }
        public int ItemQuantity { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题