Wednesday, June 10, 2015

RouteValueDictionary

I got an error recently when I enable DonutCache donutHole-based caching for a RenderAction:
Type 'System.String[]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
It seems RouteValueDictionary cannot manage IEnumerable or String[] as a parameter. The solution is simple, it's a well-known issue:
http://stackoverflow.com/questions/19960420/adding-array-of-complex-types-to-routevaluedictionary

So this is how you can use the extension method:
Html.RenderAction(
                             ActionName,
                             ControllerName,
                             new RouteValueDictionary(new 
                             {      usual properties here }));