views:

563

answers:

1

I have been working with MVC 2 and it seems that at some point of time the ModelBindingContext.ValueProvider class has been removed and replace with IValueProvider. Because of this im having trouble iterating through the ValueProvider.Keys. Here is an example and the message I receive from Code complete

private void foo(ModelBindingContext myMBC)
{
     var myImportantKeys = myMBC.ValueProvider.Keys.where(keyValue => keyValue.StartsWith("important", StringComparison.InvariantCulture);
     foreach(var importantKey in myImportantKeys)
     {

     }
}

The message I get is System.Web.MVC.IValueProvider does not contain a definition for Keys. Could someone enlighten me on how to get around this.

+2  A: 

Gosh, that code looks familiar!

You can't get a list of Key values from IValueProvider. You have to go to the source, e.g:

var keys = controllerContext.HttpContext.Request.QueryString.AllKeys.Where(...
Craig Stuntz
funny that you should respond!...but your the perfect person. n? Im trying to create a custom model binder that grabs the "important" values but triggers a routine to apply some special encoding to the values. Would this be a good way to do it?
John Hartsock