There is an error with your both suggestions: "'KeyValuePair' is 'type' and not valid in the given context."
Keep in mind it is very difficult to provide an accurate solution when you post code with compiler errors. I have no idea what your intention is.
Anyway, from your response it seems you are passing a collection of key value pairs.
@{
var kvp = ViewData["kvp"] as KeyValuePair<int, string>[];
}
Or
@{
var kvp = (KeyValuePair<int, string>[])ViewData["kvp"];
}
I typically take advantage of List<T>.
@{
var kvp = (List<KeyValuePair<int, string>>)ViewData["kvp"];
}