I'm using the MVC 2 RC. I have a custom model binder that us开发者_开发问答ed to iterate over posted form values in MVC 1.0 like this:
var values = bindingContext.ValueProvider.Where(x => x.Key.StartsWith("prefix"));
foreach (var value in values) { /* do something */ }
In version 2, I can't do this anymore. Apparently there are new implementations of IValueProvider that come with ASP.NET MVC 2.0. I think I need to somehow use FormValueProvider in my custom model binder, but I don't know how to get at it.
ValueProvider seems to be a read/write property. Have you tried this:
var formValueProvider = new FormValueProvider(controllerContext);
bindingContext.ValueProvider = formValueProvider;
I discussed this on another question as well but to be honest I haven't used it myself.
Edit: I am not sure if there is a good solution for this scenario, but I guess you might end up accessing controllerContext.HttpContext.Request. I know it doesn't feel right but if your needs are so low level I suspect that's the only way to get to them.
精彩评论