I have a function that gets a lot of data from the internet. It takes about 15 seconds to get all the data. How can I display a text (like "loading data"), while It is still loading. Right now, it looks like this:
I enter the page
My "Index" loads my "LoadData" function.
The function stores the data into ViewBags
The function returns the View
In the View:
<table class='table' id='vmTable' border='1'>
<tr>
<th>VM Name</th>
<th>Status</th>
<th>Shutdown Time</th>
<th>Service Name</th>
<th>Created Date</th>
<th>Last Modified</th>
<th>Port</th>
</tr>
@for (int i = 0; i < ViewBag.AmountOfVms; i++)
{
<tr class="tableColumn vmColumn">
<td class="vmName">@ViewBag.VMs[i, 0]</td>
<td class="vmStatus">@ViewBag.VMs[i, 1]</td>
<td class="vmShutDown">@ViewBag.VMs[i, 6]</td>
<td class="vmServiceName">@ViewBag.VMs[i, 2]</td>
<td class="vmCreatedDate">@ViewBag.VMs[i, 3]</td>
<td class="vmLastModified">@ViewBag.VMs[i, 4]</td>
<td class="vmPort">@ViewBag.VMs[i, 7]</td>
</tr>
}
</table>
Ive heard about Ajax and using Partial Views. So, can I display my table as a partial View and just say
@if (ViewBag.VMs[i, 0] == null)
{
<td>Loading...</td>
}
And then refresh the Partial View every second? And how can I run my "LoadData" function while being on the page. Or in other words: How can I just display "loading" while the ViewBag is null.
Do you have any good examples for this?¨