aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

Usage of System.Web.Mvc.CustomModelBinderAttribute? #231

Closed IanKemp closed 5 years ago

IanKemp commented 5 years ago

The CustomModelBinderAttribute class seems to promise a way to use an attribute to link a model property to use an arbitrary model binder, but unfortunately it doesn't seem to work. Other people have had the same problem.

Looking at how CustomModelBinderAttribute is used in this project, it seems that you don't intend for it to be applied on anything except types (and params) - can you confirm this?

dougbu commented 5 years ago

It looks like this question has a good answer on StackOverflow. Have you tried the second answer on the StackOverflow question. That's https://stackoverflow.com/a/18356522

IanKemp commented 5 years ago

I'm not asking how to achieve this behaviour, I'm asking why CustomModelBinderAttribute doesn't allow said behaviour out-of-the-box, and whether that is intentional or not. In other words, what is/was the design decision behind CustomModelBinderAttribute? Especially considering that e.g. https://msdn.microsoft.com/en-us/magazine/hh781022.aspx seems to imply it should work (section "Adorning Models with Custom Attributes").

As for the given solution, it is somewhat intrusive because it necessitates replacing the default model binder. That wouldn't be necessary if CustomModelBinderAttribute behaved as the linked MSDN article seems to suggest it should.

dougbu commented 5 years ago

Not supporting [CustomModelBinder] on properties was intentional. Can't say I remember the reason however.

dougbu commented 5 years ago

Thank you for your feedback. We're closing this issue as the questions asked here have been answered.