Razor 页面中的异步 @functions
Async in Razor Page @functions
我的 Razor 页面出现以下错误。
所以我改了。
现在代码可以 运行 但我收到警告。
1>obj\Debug\netcoreapp3.0\Razor\Pages\Areas.cshtml.g.cs(256,200,256,202): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
1>obj\Debug\netcoreapp3.0\Razor\Pages\Areas.cshtml.g.cs(282,200,282,202): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
谁能确切地告诉我 Razor Pages 在这里需要什么?
更新:
这是我完整的 @functions
部分。
@functions
{
async System.Threading.Tasks.Task RenderArea(Area area)
{
<tr>
<td class="@area.CssClass">
<p class="compact">
<a href="/Area/@area.Id" class="font-weight-bold">@area.Title</a>
@if (!string.IsNullOrWhiteSpace(area.Description))
{
<br />@area.Description
}
</p>
</td>
<td class="@area.CssClass">
<img src="~/images/Edit.png" class="edit-area button-img" data-id="@area.Id" title="Edit" />
<img src="~/images/Delete.png" class="delete-area button-img" data-id="@area.Id" title="Delete" />
</td>
</tr>
}
}
第一个是错误,第二个是警告。
This is the change 实现了第一个错误消息。所以这肯定是故意的。
我怀疑这个警告是由于在方法中的任何地方都没有看到单词 await
并且不理解 ~/
会导致隐含的 await
。所以我认为这可能是一个错误 should be reported to Microsoft.
但目前,我认为您除了忽略警告之外别无选择。
我的 Razor 页面出现以下错误。
所以我改了。
现在代码可以 运行 但我收到警告。
1>obj\Debug\netcoreapp3.0\Razor\Pages\Areas.cshtml.g.cs(256,200,256,202): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
1>obj\Debug\netcoreapp3.0\Razor\Pages\Areas.cshtml.g.cs(282,200,282,202): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
谁能确切地告诉我 Razor Pages 在这里需要什么?
更新:
这是我完整的 @functions
部分。
@functions
{
async System.Threading.Tasks.Task RenderArea(Area area)
{
<tr>
<td class="@area.CssClass">
<p class="compact">
<a href="/Area/@area.Id" class="font-weight-bold">@area.Title</a>
@if (!string.IsNullOrWhiteSpace(area.Description))
{
<br />@area.Description
}
</p>
</td>
<td class="@area.CssClass">
<img src="~/images/Edit.png" class="edit-area button-img" data-id="@area.Id" title="Edit" />
<img src="~/images/Delete.png" class="delete-area button-img" data-id="@area.Id" title="Delete" />
</td>
</tr>
}
}
第一个是错误,第二个是警告。
This is the change 实现了第一个错误消息。所以这肯定是故意的。
我怀疑这个警告是由于在方法中的任何地方都没有看到单词 await
并且不理解 ~/
会导致隐含的 await
。所以我认为这可能是一个错误 should be reported to Microsoft.
但目前,我认为您除了忽略警告之外别无选择。