title: asp.net core and ajax
body: <p>I'm working on ASP.NET Core application and not sure what is right way to use ajax in it.</p>
  
  <p>For example, I have model:</p>
  
  <pre><code>public class Person
      {
          public int ID { get; set; }
          public string Wiki { get; set; }
          public string Name { get; set; }
      }
  </code></pre>
  
  <p>Controller, for show list of items:</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; Index()
          {
              return View(await _context.Person.ToListAsync());
          }
  </code></pre>
  
  <p>And view:</p>
  
  <pre><code>&lt;table class="table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;                
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.Name)
                  &lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  @foreach (var item in Model) {
          &lt;tr&gt;            
              &lt;td&gt;
                  &lt;a asp-action="Details" asp-route-id="@item.ID"&gt;@Html.DisplayFor(modelItem =&gt; item.Name)&lt;/a&gt;
              &lt;/td&gt;
  
          &lt;/tr&gt;
  }
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>When I press on item I want to get item's details.</p>
  
  <p>I have action <code>Details(int? id)</code> and view Details.cshtml.</p>
  
  <p>And I created ViewModel:</p>
  
  <pre><code>public class PersonViewModel
      {
          public string Name { get; set; }
          public string Description { get; set; }
          public string Birthday { get; set; }
          public string Death { get; set; }
          public string Image { get; set; }
          public string Link { get; set; }            
      }
  </code></pre>
  
  <p>But this information I get from Wikidata using ajax.</p>
  
  <p>I can run ajax by pressing link on the item and I get json from Wikidata.</p>
  
  <p>But how I can populate ViewModel? For this I need to call action Details from ajax. But ajax usually used for get information on the current page (to avoid postback). So in this case it doesn't belong here.</p>
  
  <p>Or I can call ajax when loading Detals view and populate page information. But in this case I don't need ViewModel at all.</p>
  
  <p>What is right way to use ajax in my application?</p>