我如何将带有数据的模型从DB传递到ABP.IO布局挂钩?

我如何将带有数据的模型从DB传递到ABP.IO布局挂钩?,abp,Abp,正在尝试使用ABP.io framework 3.1设置多租户站点 我正在尝试设置视图组件与razor页面不同 看 您应该直接在视图组件类中注入服务。比如: 公共类MetaKeywordViewComponent:AbpViewComponent { 专用只读ITenantSiteDataAppService\u租户ITedataAppService; public MetaKeywordViewComponent(ITenantSiteDataAppService租户ITedataAppSer

正在尝试使用ABP.io framework 3.1设置多租户站点


我正在尝试设置视图组件与razor页面不同

您应该直接在视图组件类中注入服务。比如:

公共类MetaKeywordViewComponent:AbpViewComponent
{
专用只读ITenantSiteDataAppService\u租户ITedataAppService;
public MetaKeywordViewComponent(ITenantSiteDataAppService租户ITedataAppService)
{
_tenantSiteDataAppService=tenantSiteDataAppService;
}
公共异步任务InvokeAsync()
{
返回视图(“/Pages/Shared/Components/Head/MetaKeyword.cshtml”,
等待_tenantSiteDataAppService.GetSiteDataAsync());
}
}

此外,你可以参考

完美,我知道我忽略了一些简单而愚蠢的事情。
Public class MetaKeywordViewComponent : AbpViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync() {
        return View("/Pages/Shared/Components/Head/MetaKeyword.cshtml"); //, meta);
    }
}
@using MyCompany.MyProduct.Web.Pages.Shared.Components.Head
@model  MetaKeywordModel 

@if (Model.SiteData.Keywords.Length > 0)
{
    <meta content="@Model.SiteData.Keywords" name="keywords" />
}

 public class MetaKeywordModel : MyProductPageModel
    {
        private readonly ITenantSiteDataAppService _tenantSiteDataAppService;

        public TenantSiteDataDto SiteData { get; private set; }

        public MetaKeywordModel(ITenantSiteDataAppService tenantSiteDataAppService)
        {
            _tenantSiteDataAppService = tenantSiteDataAppService;
        }

        public virtual async Task<ActionResult> OnGetAsync()
        {
            if (CurrentTenant != null)
            {
                SiteData = await _tenantSiteDataAppService.GetSiteDataAsync();
            }

            return Page();
        }
    }
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Volo.Abp.AspNetCore.Mvc.UI.Components.LayoutHook.LayoutHookViewModel', but this ViewDataDictionary instance requires a model item of type 'MyCompany.MyProduct.TenantData.Dtos.TenantSiteDataDto'.