title: How can I get ViewBag value in ASP.NET MVC ?
body: <p>I'm using ASP.NET MVC Razor view engine, and I'm trying to use Viewbag. The following code will not work for me. In the controller I have</p>
  
  <pre><code>ViewBag.courses = new List&lt;dynamic&gt;();
  ViewBag.courses.Add(new { Name = "Math" });
  </code></pre>
  
  <p>and then in the view I have</p>
  
  <pre><code>@foreach(dynamic course in ViewBag.courses)
  {
      &lt;li&gt;@course.Name&lt;/li&gt;
  }
  </code></pre>
  
  <p>But it gives me an error saying the object course does not have a definition for Name. The debugger gives me the value, and shows everything correctly. Is there any way to get this to work? (I have a workaround already, I just would rather use this).</p>
  
  <p>Thanks in advance.</p>