问题
I am trying to create my first View Component in my MVC project but have come to a halt. When I try to invoke my View Component from the razor view page I get an error that states: "The name 'await' does not exist in the current context".
Code I use to call the View Component:
@await Component.InvokeAsync("Example")
View Component class:
namespace MyWebApp.ViewComponents
{
public class ExampleViewComponent : ViewComponent
{
public IViewComponentResult Invoke()
{
var user = Account.GetCurrent();
return View(user);
}
}
}
View Component razor view file location: Views/Shared/Components/Example/Default.cshtml
View Component class file location: ViewComponents/ExampleViewComponent.cs
I have mostly been following this tutorial: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.1
SOLVED : Check comments
来源:https://stackoverflow.com/questions/52373631/asp-net-mvc-compiler-error-when-trying-to-invoke-view-component-from-view-page