首页 > 解决方案 > Asp.Net Core 2.1 在 Head 标签之间使用 ViewComponents 动态获取元数据

问题描述

我想从管理面板动态地将元数据添加到 SEO 的布局页面。样本:

<meta content="" name="description" />
<meta content="XXX" name="author" />

在 MVC5 中,我使用:
<head> @Html.Action("GetMetatags", "Home") </head>

并轻松获得它们。但是在 Asp.Net Core 2.1 中,我尝试使用 ViewComponents 而不是像这样的局部视图:

<head> 
     @await Component.InvokeAsync("MetaDatasForSEO") 
</head> 

问题:我可以正确获取元数据,但不能在<head>标签之间。只是在<Body>标签中......所以它不起作用。感谢帮助...

标签: asp.net-coremeta-tagsasp.net-core-2.1asp.net-core-viewcomponent

解决方案


推荐阅读