title: async/await in MVC controller's action
body: <p>I have an <code>Index</code> action in ASP.net MVC controller. This action, calls (among other things) a private action that do a count on a SQL table with large set of rows. The returned number will be inserted in a view bag property.</p>
  
  <pre><code>public ActionResult Index() 
  {
      // do things
      ViewBag.NumberOfRows = NumberOfRows();
      return View();
  }
  
  private string NumberOfRows()
  {
      // sql connection and row count
      return numberOfRows;
  }
  </code></pre>
  
  <p>This works but I can't see the Index page until <em>everything</em> is executed, even the row count.
  I would, instead, <code>Index</code> action to immediately complete, even if private function hasn't been completed yet. Than when count has been completed set a value to the view bag property.
  Right now I've done this:</p>
  
  <pre><code>private async Task&lt;string&gt; NumberOfRows()
  {
      SqlConnection connection = new SqlConnection(connString);
      SqlCommand cmd = new SqlCommand();
      SqlDataReader reader;
  
      cmd.CommandText = "SELECT SUM (row_count) FROM sys.dm_db_partition_stats WHERE object_id=OBJECT_ID('aTable') AND (index_id=0 or index_id=1)";
      cmd.CommandType = CommandType.Text;
      cmd.Connection = connection;
  
      await connection.OpenAsync();
  
      reader = await cmd.ExecuteReaderAsync();
      string numberOfRows = "N/A";
      while (await reader.ReadAsync())
      {
          numberOfRows = reader.GetInt64(0).ToString();
      }
  
      connection.Close();
  
      return numberOfRows ;
  }
  
  public async Task&lt;ActionResult&gt; Index(FormCollection form){
      // do things;
      ViewBag.NumberOfRows = await NumberOfRows();
      return View();
  }
  </code></pre>
  
  <p>This works. But is this really async? Am I miss something, there are other way of doing this?</p>