[英]Multiple parameters with EventCallback in Blazor without creating a class and pass it
One year go a created a project where i passed multiple parameters following the answers on this question: Blazor EventCallback with Multiple Params - how to respond to event in parent host control一年去创建了一个项目,我在这个问题的答案之后传递了多个参数: Blazor EventCallback with Multiple Params - how to respond to event in parent host control
When i tried now in .net 6 is not working(it is working with creating a class and passing the parameters to the fiels there, but for me is not the clean solution).当我现在在.net 6中尝试时不起作用(它正在创建一个类并将参数传递给那里的字段,但对我来说不是干净的解决方案)。
Parent component:父组件:
<MultipleParamsComp OnHandle="@((args) => await HandleParams(((int, string))args))" />
<p>@BaseId</p>
<p>@BaseString</p>
@code {
private int BaseId = 0;
private string BaseString = string.Empty;
private async Task HandleParams((int, string) args)
{
BaseId = args.Item1;
BaseString = args.Item2;
}
}
Child Component:子组件:
<h4>Child Component</h4>
<button class="btn btn-primary" @onclick="(() => HandleMultipleParams(id))">
Testing
</button>
@code {
private int id = 0;
private string Name = "something";
[Parameter]
public EventCallback<(int, string)> OnHandle { get; set; }
private async Task HandleMultipleParams(int customerId)
{
customerId++;
await OnHandle.InvokeAsync((customerId, Name));
}
}
Output输出
Severity Code Description Project File Line Suppression State Error CS1001 Identifier expected BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90 Active严重性代码描述项目文件行抑制状态错误 CS1001 标识符预期 BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90积极的
Severity Code Description Project File Line Suppression State Error CS0119 'string' is a type, which is not valid in the given context BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90 Active严重性代码 描述 项目文件行抑制状态错误 CS0119 'string' 是一种类型,在给定的上下文 BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk 中无效.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90 活动
Severity Code Description Project File Line Suppression State Error CS0119 'int' is a type, which is not valid in the given context BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90 Active严重性代码 描述 项目文件行抑制状态错误 CS0119 'int' 是一种类型,在给定的上下文 BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk 中无效.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90 活动
Severity Code Description Project File Line Suppression State Error CS0119 'EventCallback' is a type, which is not valid in the given context BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90 Active严重性代码 描述 项目文件行抑制状态错误 CS0119 'EventCallback' 是一种类型,在给定的上下文 BlazorTheory E:\Programare\Blazor\BlazorTheory\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk 中无效.Razor.SourceGenerators.RazorSourceGenerator\Theory_EventCallBack_Other_Examples_Passing_multiple_params_in_function_BaseComponent1_razor.g.cs 90 活动
Maybe i lack some theory of delegates or EventCallback and how they work behind the scene(any good documentation links helps).也许我缺乏一些代表或 EventCallback 的理论以及它们如何在幕后工作(任何好的文档链接都有帮助)。
Ty u.你。
Please take a look at following question- Blazor EventCallback with Multiple Params - how to respond to event in parent host control请查看以下问题- Blazor EventCallback with Multiple Params - 如何响应父主机控件中的事件
await NewDayScrolledIntoView.InvokeAsync((p1, p2, p3));
<ShiftCardScroller NewDayScrolledIntoView="@((args)=> NewDayInView(args.Item1,args.Item2,args.Item3))" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.