【发布时间】:2013-01-15 15:38:37
【问题描述】:
我发现了几个类似下面的问题,但我发现在以前的 MVC 版本中,MVC 4 中有什么新的东西吗?
Optional Dictionary Parameter in MVC 3 Controller Action
更新:提供一些代码来帮助未来的访问者
public class QueryStringDictionaryBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var querystrings = controllerContext.HttpContext.Request.QueryString;
return querystrings.Cast<string>()
.Select(s => new { Key = s, Value = querystrings[s] })
.ToDictionary(p => p.Key, p => p.Value);
}
}
【问题讨论】:
标签: dictionary parameters asp.net-mvc-4 controller action