Compilation error in foreach statement while looping an object of type 'System.Threading.Tasks.Task<System.Collections.Generic.List' i
<p>In the Asp.Net Project MVC with SignalR, I am trying to iterate over a object returned by Service in the Javascript Client. I get the below compile error for the foreach statement present in the below code</p>

<p>foreach statement cannot operate on variables of type 'System.Threading.Tasks.Task>' because 'System.Threading.Tasks.Task>' does not contain a public definition for 'GetEnumerator'</p>

<p>Can someone advise what changes should be done either in View/Service call ?</p>

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

<pre><code>  @model  System.Threading.Tasks.Task&lt;List&lt;JobCurrentStatusDetails&gt;&gt;

   &lt;script type="text/javascript"&gt;


                var connection = $.hubConnection();
                var hub = connection.createHubProxy("JobDetailsHub");
                hub.on('updateData',function(jSonRefreshData){
                    console.log(jSonRefreshData);
                });
                hub.invoke('NotifyUpdates').done(function(jSonRefreshData){

                    @Model = jSonRefreshData
                    @{int countTiles = 0;}
                    @foreach(item in Model)
                    {
                        if(item.color == "red")
                        {}
                         if(item.color == "green")
                         {}
  }
                });
    &lt;/script&gt;
</code></pre>

<p>Adding Server Side code</p>

<pre><code> public async Task&lt;List&lt;JobCurrentStatusDetails&gt;&gt; NotifyUpdates()
        {
       var hubContext = lobalHost.ConnectionManager.GetHubContext&lt;JobDetailsHub&gt;    ();
       if (hubContext != null)
       {
           db =  DataAccess.DataAccessModels.GetDashboardCounts();

           return await hubContext.Clients.All.updateData(db);

       }
       else return null;
   }
</code></pre>

<p>The Controller code is below :</p>

<pre><code>public  ActionResult Index()
        {
            DataAccess da = new DataAccess();
            var jobDetailService = new JobDetailsService(da);

            return View(jobDetailService.NotifyUpdates());


        }
</code></pre>