要在ASP.Net Core MVC中在渲染结束时更新head标签,可以使用以下解决方法:
@RenderSection("Head", required: false)
@{
ViewData["Title"] = "Home";
}
@section Head {
}
public IActionResult Index()
{
ViewData["Title"] = "Home";
ViewData["Description"] = "This is the Home page";
return View();
}
@RenderSection("Head", required: false)
@if (!string.IsNullOrEmpty(ViewData["Description"] as string))
{
}
通过以上步骤,当渲染结束时,head标签的内容将会根据视图中传递的数据进行更新。