ASP.NET MVC - C# - Define Key Value Pair for use in Razor View
<p>I have an ASP.NET MVC app. My app needs to display breadcrumbs representing the user's location in the app. In an effort to do this, I wanted to have something like the following in a master layout page:</p>

<pre><code>@foreach(var link in ViewBag["Links"])
{
  &lt;div&gt;|&lt;/div&gt;
  &lt;a href="@link.url"&gt;@link.text&lt;/a&gt;
}
</code></pre>

<p>Then, in each view, I'd have something like the following at the top:</p>

<pre><code>@{
    Layout = "~/Views/Layouts/_Breadcrumbed.cshtml";
    ViewBag.Links = new Dictionary&lt;string, string&gt;()
    {
        { "Home", "/home" },
        { "Parent", "/parent" }
    };
}
</code></pre>

<p>When this code executes, I get the following error:</p>

<pre><code>Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject'
</code></pre>

<p>I do not understand why I'm getting that. Am I doing down the correct path for creating a breadcrumb? If not, what approach is better?</p>