C# Asp.Net视图呈现意外输出
为什么这段代码工作得很好,按预期输出HTML并C# Asp.Net视图呈现意外输出,c#,asp.net,asp.net-mvc,asp.net-core,C#,Asp.net,Asp.net Mvc,Asp.net Core,为什么这段代码工作得很好,按预期输出HTML并 <div class="page home-page custom-container d-flex flex-column"> @await Component.InvokeAsync("PersonalizedProducts") @await Component.InvokeAsync("RecommendedProducts") @await Component.InvokeAsync("Suggeste
<div class="page home-page custom-container d-flex flex-column">
@await Component.InvokeAsync("PersonalizedProducts")
@await Component.InvokeAsync("RecommendedProducts")
@await Component.InvokeAsync("SuggestedProducts")
@await Component.InvokeAsync("HomePageProducts")
@await Component.InvokeAsync("HomePageNewProducts")
@await Component.InvokeAsync("CategoryFeaturedProducts")
</div>
@wait Component.InvokeAsync(“个性化产品”)
@wait Component.InvokeAsync(“推荐产品”)
@wait Component.InvokeAsync(“SuggestedProducts”)
@wait Component.InvokeAsync(“HomePageProducts”)
@wait Component.InvokeAsync(“HomePageNewProducts”)
@wait Component.InvokeAsync(“CategoryFeaturedProducts”)
…这个不起作用:
<div class="page home-page custom-container d-flex flex-column">
@{
var tasks = new List<Task>();
tasks.Add(Component.InvokeAsync("PersonalizedProducts"));
tasks.Add(Component.InvokeAsync("RecommendedProducts"));
tasks.Add(Component.InvokeAsync("SuggestedProducts"));
tasks.Add(Component.InvokeAsync("HomePageProducts"));
tasks.Add(Component.InvokeAsync("HomePageNewProducts"));
tasks.Add(Component.InvokeAsync("CategoryFeaturedProducts"));
await Task.WhenAll(tasks);
}
</div>
@{
var tasks=新列表();
tasks.Add(Component.InvokeAsync(“PersonalizedProducts”);
添加(Component.InvokeAsync(“推荐产品”);
tasks.Add(Component.InvokeAsync(“SuggestedProducts”);
添加(Component.InvokeAsync(“HomePageProducts”);
添加(Component.InvokeAsync(“HomePageNewProducts”);
添加(Component.InvokeAsync(“CategoryFeaturedProducts”);
等待任务。何时(任务);
}
上面提到的组件彼此之间100%独立,只共享一个数据库,它们不会更改数据库,因为这些是仅获取组件…如果您希望html输出,则需要添加更多代码以输出html:
<div class="page home-page custom-container d-flex flex-column">
@{
var tasks = new List<Task>();
tasks.Add(Component.InvokeAsync("PersonalizedProducts"));
tasks.Add(Component.InvokeAsync("RecommendedProducts"));
tasks.Add(Component.InvokeAsync("SuggestedProducts"));
tasks.Add(Component.InvokeAsync("HomePageProducts"));
tasks.Add(Component.InvokeAsync("HomePageNewProducts"));
tasks.Add(Component.InvokeAsync("CategoryFeaturedProducts"));
await Task.WhenAll(tasks);
foreach( var t in tasks)
{
var var1 = await t;
@var1;
}
}
</div>
@{
var tasks=新列表();
tasks.Add(Component.InvokeAsync(“PersonalizedProducts”);
添加(Component.InvokeAsync(“推荐产品”);
tasks.Add(Component.InvokeAsync(“SuggestedProducts”);
添加(Component.InvokeAsync(“HomePageProducts”);
添加(Component.InvokeAsync(“HomePageNewProducts”);
添加(Component.InvokeAsync(“CategoryFeaturedProducts”);
等待任务。何时(任务);
foreach(任务中的var t)
{
var var1=等待t;
@var1;
}
}
您遇到了什么错误?你能不能说没有实际的错误,页面只是一片空白…几乎没有!秘密在于声明列表
!