Component.InvokeAsync() not showing my viewComponent!

Hamed Vaziri 131 Reputation points


in my core razor pages project, in my index page, i have a simple code as follow :

if (Model._attachments.Count == 0)
		await Component.InvokeAsync("NoData");
		<div style="height: 100vh;" class="d-flex flex-column justify-content-between">

In my above code, i have a property named '_attachments' which returns from my dbContext. Now, before i show main content, check _attachment property count, If it's count == 0, then display my custom viewComponent named 'NoData'. my problem is that it display a blank page when _attachment.count == 0!

Here is my viewComponent code :

<div class="container font-iranSans mt-5" dir="rtl">
    <a href="" class="text-decoration-none">
        <p>شبکه سلامت ایران</p>
    <hr />

    <div class="container text-center">
        <img class=" img-fluid imgCustom" src="img/IranHealthLogo.png" alt="شبکه سلامت ایران">
    <div class="alert alert-danger mx-auto mt-2 w-50 text-center pt-4">
        <p>اطلاعاتی برای نمایش وجود ندارد!</p>
    <div class="container text-center footerBox rounded-2 pt-1 mt-5">
        <a href="" class="text-decoration-none">

Where is the problem & how to solve it?

Thanks in advance

A set of technologies in the .NET Framework for building web applications and XML web services.
3,791 questions
0 comments No comments
{count} votes

Accepted answer
  1. Chen Li - MSFT 1,211 Reputation points

    Hi @Hamed Vaziri,

    Please add the @ symbol before await Component.InvokeAsync("NoData"); :

    @await Component.InvokeAsync("NoData");   

    For more details, please check this official document.

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    Chen Li

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful