Search code examples
c#asp.net-coreasp.net-core-mvcasp.net-core-viewcomponent

ASP.NET Core view components returning blank pages


I have a view component I'm invoking like so:

@{
    await Component.InvokeAsync("Edit", new { config = new List<EditConfiguration>() });
}

It looks like this:

// Need to make individual view components for every page
public class EditViewComponent : ViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync(List<EditConfiguration> config)
    {
        return View("~/Views/Edit/Edit.cshtml", config);
    }
}

I've confirmed with breakpoints that the InvokeAsync method and Edit.cshtml are being entered by the code.

But nothing is actually returned by InvokeAsync, the page is just blank. Even if I just change Edit.cshtml so that it's some text and nothing else so there's no chance of internal page error. Removed the parameter/model, same thing. It's just not returning anything.

What do I do about this?


Solution

  • Change your code from:

    @{
        await Component.InvokeAsync("Edit", new { config = new List<EditConfiguration>() });
    }
    

    To:

    @await Component.InvokeAsync("Edit",new { config = new List<EditConfiguration>() })