Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!