Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

301
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda