I have adapted a couple of examples and think this is more or less correct, but I am getting errors in odd places. Clearly I have stuffed something up.
The view component:
using Eva804.Data;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using Eva804.Models;
namespace Eva804.ViewComponents
{
public class Last6ClosedJobsViewComponent : ViewComponent
{
private readonly Eva804Context ctx;
public Last6ClosedJobsViewComponent(Eva804Context context)
{
ctx = context;
}
public async Task<IViewComponentResult> InvokeAsync(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);
}
}
}I am getting loverly red squiggles on:
public class Last6ClosedJobsViewComponent : ViewComponent
ViewComponent is not being accepted producing a namespace but is used like a variable
And on:
return View(jobs);
Where View is saying a namespace but is used like a type.
Clearly I am making some error, but I cannot see it. Where should I look? Am I missing a directive or something?