ASP.NET Core view component 运行时报错:"A view component must return a non-null value"
在一个 asp.net core 3.0 preview 5 中实现了一个 view component ,运行时出现下面的错误:
System.InvalidOperationException: A view component must return a non-null value.
at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.CoerceToViewComponentResult(Object value)InvokeAsync 方法的实现如下:
public async Task<IViewComponentResult> InvokeAsync(AggSiteModel model)
{
if (model == null) return null;
model.Posts ??= await GetPostsAsync(model);
if (model.Posts == null) return null;
return View("PostList", model.Posts);
}请问如何解决?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1414/viewspace-3136608/ ,如需转载,请注明出处,否则将追究法律责任。