ViewDataDictionary
implements IDictionary<string, object>
.
IDictionary<string, object>
is essentially a collection of KeyValuePair<string, object>
.
Your ViewDataDictionary
initializer (outer curly braces) contains another set of curly braces that represents a KeyValuePair<string, object>
initializer.
The reason this is possible is explained in this answer.
You can Add
multiple items by comma separating the KeyValuePair<string, object>
initializers:
var data = new ViewDataDictionary
{
{ "Name", "Value" },
{ "Name2", "Value2" }
};
Is the same as:
var data = new ViewDataDictionary
{
new KeyValuePair<string, object>("Name", "Value"),
new KeyValuePair<string, object>("Name2", "Value2")
};
Essentially, the inner curly braces are nice syntax for initializing KeyValuePair<string, object>
objects.