Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Html.IHtmlContent] in ViewComponent Section of View

I am new to view component and don't understand why I am getting this error at all.

public class Last6ClosedJobsViewComponent :  ViewComponent
{
    private readonly Eva804Context ctx;

    public Last6ClosedJobsViewComponent(Eva804Context context)
    {
        ctx = context;
    }

    public IViewComponentResult Invoke(int id)
    {
        var jobs = from j in ctx.Job
                   .Include(j => j.Site)
                   .Include(j => j.WaterBody)
                   .Where(j => j.Site.SiteID == id && j.InvoiceDate != null)
                   .OrderByDescending(j => j.BookingDate)
                   .Take(6)
                   select j;

        return View(jobs);
    }

}

Then in the default view I am simply trying to show a list of booking dates, at this stage:

@model IEnumerable<Eva804.Models.Job>

<h3>Recently Invoiced Jobs</h3>
<ul>
@foreach (var j in Model)
{
    <li>@j.BookingDate</li>

}
</ul>

Then in site details I have the following:

<div class="alert alert-success">@Component.InvokeAsync("Last6ClosedJobs",Model.SiteID)</div>

All of which looks correct as far as I can see, compared to the examples I am working against.

This is then showing in the view a loverly green section, nice and wording as: System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Html.IHtmlContent]

How do I find this error? Where should I look? Is there something wrong with my code I cant see?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need @await to handle ansynchronous calls, like this:

<div class="alert alert-success">@await Component.InvokeAsync("Last6ClosedJobs",Model.SiteID)</div>

InvokeAsync returns a Task, then @await waits on the task and when the task is finished, it returns the result.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda