Pass ViewBag with List to view for foreach loop
<p>I am passing a query result from the controller to a view through a Viewbag but when looping through the Viewbag result I get the error 'object' does not contain a definition for 'Ratings' even though it does show up when debugging. I am not using a model for the query so I cannot cast the list.</p>

<p>How do I send through the list from the query or the query results itself to the view to so I loop through and extract the data?</p>

<p><strong>Controller</strong></p>

<pre><code>var AppQuery = (from ans in db.Answers
                        join ques in db.Questions on ans.QuestionID equals ques.QuestionID
                        join resp in db.Responses on ans.ResponseID equals resp.ResponseID
                        join sec in db.Sections on ques.SectionID equals sec.SectionID
                        where resp.ResponseID == ID &amp;&amp; ques.SubSectionName != null
                        select new { SectionName = sec.SectionName, RatingAnswer = ans.RatingAnswer })
 .GroupBy(a =&gt; a.SectionName)
 .Select(a =&gt; new { SectionName = a.Key, Ratings = a.Sum(s =&gt; s.RatingAnswer) });


        ViewBag.Results = AppQuery.ToList();
</code></pre>

<p><strong>View</strong></p>

<pre><code>    @{var Results = ViewBag.Results;}

 @foreach (var item in Results)
                                        {
                                            var style = "active";
                                            var condition = "";

                                            if (item.Ratings &gt;= 90)
                                            {
                                                style = "success";
                                                condition = "Excellent";
                                            }
                                            else if (item.Ratings &lt; 50)
                                            {
                                                style = "danger";
                                                condition = "Critical";
                                            }
                                            else
                                            {
                                                style = "active";
                                                condition = "Stable";
                                            }
                                            &lt;tr class="@style"&gt;
                                                &lt;td&gt;@item.SectionName&lt;/td&gt;
                                                &lt;td&gt;@item.Ratings&lt;/td&gt;
                                                &lt;td&gt;@condition&lt;/td&gt;

                                            &lt;/tr&gt;

                                        }
</code></pre>

<p>Thanks for the help!</p>