Component.InvokeAsync() not showing my viewComponent!

Hamed Vaziri 131 Reputation points
2023-05-02T20:32:06.9033333+00:00

Hi

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

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

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="http://www.iranhealth.net" class="text-decoration-none">
        <p>شبکه سلامت ایران</p>
    </a>
    <hr />

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

Where is the problem & how to solve it?

Thanks in advance

ASP.NET Core
ASP.NET Core
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
    2023-05-03T01:46:48.4266667+00:00

    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