简体   繁体   English

foreach 循环中的 Component.InvokeAsync 不起作用

[英]Component.InvokeAsync in foreach loop doesn't work

I have problem with display Component in Foreach loop:我在 Foreach 循环中显示组件有问题:

I. First case - component work:一、第一种情况——组件工作:

I create simple component (named HelloComponent) like that:我创建了这样的简单组件(名为 HelloComponent):

<h3>Hello Adam!</h3>

When i run it using:当我使用以下方法运行它时:

///My code before component

await Component.InvokeAsync("HelloComponent");

///My code after component

Everythink work, and i got: Everythink工作,我得到:

///My code before component

Hello Adam!

///My code after component

II.二、 Second case - component doesn't work:第二种情况 - 组件不起作用:

In View where i run component my code looks like:在我运行组件的视图中,我的代码如下所示:

@{
    List<string> options = new List<string>();
    options.Add("Adam");
    options.Add("Adrian");
    options.Add("Bart");   
}

///My code before component

@foreach(var item in options)
{
    <h3>Test header</h3>
    await Component.InvokeAsync("HouseOptionsComponent");
}

///My code after component

I got:我有:

///My code before component

Test header
Test header
Test header

///My code after component

The foreach loop runs three times but does not get the component content. foreach 循环运行了 3 次,但没有获取到组件内容。 I believe I should have received:我相信我应该收到:

///My code before component

Test header
Hello Adam!
Test header
Hello Adam!
Test header
Hello Adam!

///My code after component
`Component.InvokeAsync("HelloComponent");`

and

`Component.InvokeAsync("HouseOptionsComponent");`

Please check the Name of view component, you are invoking different View.请检查视图组件的名称,您正在调用不同的视图。 Try to change the view name from HouseOptionsComponent to HelloComponent .尝试将视图名称从HouseOptionsComponent更改为HelloComponent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM