views:

186

answers:

2

I'm using the MVC 2 RC. I have a custom model binder that used 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.

A: 

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.

Maxwell Troy Milton King
I guess that's how you can get to the FormValueProvider, but how can iterate form values?
Ronnie Overby
+1  A: 

Check out this link : http://mgolchin.net/posts/19/dive-deep-into-mvc-ivalueprovider

Hope this helps.

ali62b