[英]Render partial view every second passing a parameter in Razor pages
I have a table like this:我有一张这样的表:
@page
@model MyApp.Pages.IndexModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery AntiForgery;
@{
ViewData["Title"] = "MyApp";
}
<div class="container-fluid">
<div class="row">
<div class="col-12 text-center p-3">
<table class="table table-striped" id="infoTable">
<tr class="table-secondary">
<th>
<label>Port</label>
</th>
<th>
<label>Name</label>
</th>
<th>
<label>Type</label>
</th>
<th>
<label>Value</label>
</th>
<th>
<label>Last update</label>
</th>
</tr>
@if (Model.Data != null)
{
@if (Model.Data.Count > 0)
{
@foreach (var item in Model.Data)
{
String genID = item.port.ToString();
<tr id="@(genID)">
<td>@item.port</td>
<td>@item.name</td>
<td>@item.varType</td>
@{Html.RenderPartial("_Value", item);}
@{Html.RenderPartial("_LastUpdate", item);}
</tr>
}
}
else
{
<tr>
<td>Model has no data.(Index)</td>
</tr>
}
}
else
{
<tr>
<td>Model is null. (Index)</td>
</tr>
}
</table>
</div>
</div>
</div>
I also have two partial views:我也有两个部分观点:
_Values _值
@model Models.Variable
<td>
@Model.value.ToString().Replace(";", "");
</td>
_LastUpdates _上次更新
@model Models.Variable
<td>
@Model.lastUpdate.ToString().Replace(";","");
</td>
I would like to automatically update the value and last update of every row every second.我想每秒自动更新每一行的值和最后一次更新。
In my model I have:在我的模型中,我有:
public PartialViewResult OnGetValuePartial(string name)
{
acquireFilterOptions();
Data = Utils.fetchInputs();
Models.Variable d = Data.Where(x => x.name == name).First();
return Partial("_Value", d);
}
public PartialViewResult OnGetLastUpdatePartial(string name)
{
acquireFilterOptions();
Data = Utils.fetchInputs();
Models.Variable d = Data.Where(x => x.name == name).First();
return Partial("_LastUpdate", d);
}
And I know that I need to send an AJAX call somewhere in there every second to get the updated value, but I don't know where or what to put in the said call to receive the values I need for aech row.而且我知道我需要每秒在那里的某个地方发送一个 AJAX 调用来获取更新的值,但我不知道在所述调用中放置的位置或内容以接收 aech 行所需的值。
Any help with this would be highly appreciated, thanks in advance for everything.对此的任何帮助将不胜感激,在此先感谢您所做的一切。
You should not update every second, that´s infinite work for the server.您不应该每秒更新一次,这对服务器来说是无限的工作。 Instead, you should look into Observable Pattern.
相反,您应该研究 Observable 模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.