Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 11
    This may violate SRP and/or SoC, but you can easily make this also inherit from ModelBinderAttribute so it can be used directly instead of the laborious syntax using the typeof() argument. All you have to do is inherit like so: CommaDelimitedArrayModelBinder : ModelBinderAttribute, IModelBinder and then provide a default constructor that pushes the type definition down to the base class: public CommaDelimitedArrayModelBinder() : base(typeof(CommaDelimitedArrayModelBinder)) { }. Commented Jan 11, 2016 at 22:49
  • Otherwise, I really like this solution and am using it in my project, so... thanks. :) Commented Jan 11, 2016 at 22:50
  • Aa a side note, this solution doesn't work with generics like System.Collections.Generic.List<long> as bindingContext.ModelType.GetElementType() only support System.Array types Commented Jan 12, 2016 at 10:02
  • @ViRuSTriNiTy: This question and the answer specifically talk about Arrays. If you need a generic list based solution, that's fairly trivial to implement. Feel free to raise a separate question if you're not sure how to go about that. Commented Jan 12, 2016 at 17:06
  • 2
    @codeMonkey: putting the array into the body makes good sense for a POST request, but what about GET requests? These usually have no content in the body. Commented Aug 14, 2016 at 19:17