本文描述了该问题和解决方法。(有一个小错误,因为GetModel
应该命名GetCustomerId
)不支持传递参数,正如异常所说。
你可以等待 ASP.NET Core 3.1,在那里将恢复传递参数的能力。
我已经为像这样的参数实现了第一篇文章中的解决方案OperationId
- 剃须刀组件的代码:
using Microsoft.JSInterop;
[Inject]
protected IJSRuntime jrt { get; set; }
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
try
{
var oid = await jrt.InvokeAsync<string>("GetOperationId");
int opid;
if (int.TryParse(oid, out opid))
OperationId = opid;
}
catch (Exception ex)
{
ls?.LogException(ex, "Sortiment.OnAfterRenderAsync");
}
//This code was moved from OnInitializedAsync which executes without parameter value
if (OperationId.HasValue)
sortiment = await ProductService.GetSortimentAsync(null, OperationId, Odpady);
else
productFilter = await ProductService.GetProductFilterAsync();
StateHasChanged(); //Necessary, because the StateHasChanged does not fire automatically here
}
}
并将其添加到托管 Razor 页面:
@section Header
{
<script>
function GetOperationId() {
return "@Model.OperationId";
}
</script>
}
此解决方法仅适用于RenderMode.Server
.