title: asp.net Core View Component executed but markup not rendered
body: <p>I have an ASP.NET Core 1.1 web application developed with VS.2017 and I decided to put some of the view functionality in a view component (have done others before).</p>
  
  <p>This view component fetches a Dictionary collection of permissions associated to a user ID and displays them in a nice table. When I put it as part of the page (not VC) it works. But when I use it as a view component the component's HTML is never rendered.</p>
  
  <p>I placed a breakpoint in the view component and it triggers, I see the View(granted) return statement return a populated list so up until there execution is as expected.</p>
  
  <p>Then I placed a breakpoint in the ViewComponent's default.cshtml code section at the top the @{ some code here } and that breakpoint triggers as well, so the view component's Default.cshtml file is found. This Default.cshtml has some markup to render a table, therein within the table I have a @foreach() statement and when do a "Run to cursor" to that precise location -the loop that iterates- it triggers as well so it is iterating through the collection.</p>
  
  <p>But after all that the main view looks as if the view component isn't there, none of the HTML found in the Default.cshtml is rendered even though it was found and executed. What am I missing here? so far my impression has been that VS.2017 (with all its updates) is not very stable.</p>
  
  <p>Default.cshtml</p>
  
  <pre><code>@using ACME.AspNetCore.Permissions.Infrastructure.Authorization
  @model Dictionary&lt;Permission, string&gt;
  @{ 
      ViewBag.UserName = "xxx";
      Model.Add(Permission.Permission1, "test");
  }
  
  &lt;h1&gt;Component Output&lt;/h1&gt;
  &lt;div class="well well-lg"&gt;
  &lt;table class="table table-hover"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Permission&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th class="text-center"&gt;Status&lt;/th&gt;
              &lt;th class="text-center"&gt;Revoke it!&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @foreach (var dictentry in Model)
          {
              &lt;tr&gt;
                  &lt;td&gt;@dictentry.Key.ToString()&lt;/td&gt;
                  &lt;td&gt;@dictentry.Value&lt;/td&gt;
                  &lt;td class="text-center"&gt;&lt;span class="glyphicon glyphicon-ok" style="color:green;"&gt;&lt;/span&gt;&lt;/td&gt;
                  &lt;td class="text-center"&gt;&lt;a asp-action="RevokePermission" asp-route-id="@ViewBag.UserName" asp-route-pid="@dictentry.Key.ToString()"&gt;&lt;span class="glyphicon glyphicon-thumbs-down" style="color:red;"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
      &lt;tfoot&gt;&lt;p class="alert alert-success"&gt;&lt;span class="glyphicon glyphicon-eye-open"&gt;&lt;/span&gt; Granted permissions&lt;/p&gt;&lt;/tfoot&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>GrantedPermissionsViewComponent.cs</p>
  
  <pre><code> [ViewComponent(Name = "GrantedPermissions")]
   public class GrantedPermissionsViewComponent : ViewComponent {
       private readonly ApplicationDbContext _context;
       public GrantedPermissionsViewComponent(ApplicationDbContext context) : base()
      {
          _context = context;
      }
  
      public async Task&lt;IViewComponentResult&gt; InvokeAsync(string emailOrUserId)
      {
          string id;
          Guid UID;
          if (Guid.TryParse(emailOrUserId, out UID))
          {   // THE PARAMETER WAS A GUID, THUS A USER ID FROM IDENTITY DATABASE
              id = emailOrUserId;
          }
          else
          {   // THE PARAMETER IS ASSUMED TO BE AN EMAIL/USERNAME FROM WHICH WE CAN DERIVE THE USER ID
              id = _context.Users.Where(u =&gt; u.Email == emailOrUserId.Trim()).Select(s =&gt; s.Id).FirstOrDefault();
          }
  
          Dictionary&lt;Permission, string&gt; granted = GetOwnerPermissions(id);
          return View(granted);            
      }
  
      private Dictionary&lt;Permission, string&gt; GetOwnerPermissions(string userId) 
      {
          Dictionary&lt;Permission, string&gt; granted;
          granted = _context.UserPermissions.Where(u =&gt; u.ApplicationUserId == userId)
                                                  .Select(t =&gt; new { t.Permission })
                                                  .AsEnumerable() // to clients memory
                                                  .Select(o =&gt; new KeyValuePair&lt;Permission, string&gt;(o.Permission, o.Permission.Description()))
                                                  .ToList()
                                                  .ToDictionary(x =&gt; x.Key, x =&gt; x.Value);
  
          return granted;
      }
   }
  </code></pre>
  
  <p>So why on earth is it triggering on the component's code as well as on the component's view (default.cshtml) and yet it does not render the HTML code found therein?</p>
  
  <p>Component invokation in the main view:</p>
  
  <pre><code>@{await Component.InvokeAsync&lt;GrantedPermissionsViewComponent&gt;(
      new { emailOrUserId = ViewBag.UserName });
  }
  </code></pre>
  
  <p>NOTE</p>
  
  <ul>
  <li>The InvokeAsync is actually executing synchronously (per warning) because I could not find a way to have GetOwnerPermissions to await on anything... But that is not the problem.</li>
  </ul>