IValueProvider in MVC 2 RC 2

泪湿孤枕 提交于 2019-12-01 02:16:24

问题


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.


回答1:


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(...


来源:https://stackoverflow.com/questions/2290473/ivalueprovider-in-mvc-2-rc-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!