I am working on an ASP.NET Core application and am not sure if this is the correct way to use ajax in it.
For example, I have a model:
public class Person
{
public int ID { get; set; }
public string Wiki { get; set; }
public string Name { get; set; }
}
Controller for displaying a list of items:
public async Task<IActionResult> Index()
{
return View(await _context.Person.ToListAsync());
}
And view:
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
<a asp-action="Details" asp-route-id="@item.ID">@Html.DisplayFor(modelItem => item.Name)</a>
</td>
</tr>
}
</tbody>
</table>
When I click on an item, I want to get the details of the item.
I have an action Details(int? id)and view Details.cshtml.
And I created a ViewModel:
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; }
}
But this information I get from Wikidata using ajax.
I can start ajax by clicking on the element link and I get json from Wikidata.
But how can I populate the ViewModel? To do this, I need to call action Details from ajax. But ajax is usually used to get information about the current page (to avoid postback). So in this case he does not belong here.
ajax Detiles . ViewModel.
ajax ?