C# ASP MVC核心:ViewComponent内部HTML
我正在尝试使用ViewComponents在ASP MVC Core 2.1中封装重复的HTML块 标记帮助器使它看起来很简单:C# ASP MVC核心:ViewComponent内部HTML,c#,.net,asp.net-core,C#,.net,Asp.net Core,我正在尝试使用ViewComponents在ASP MVC Core 2.1中封装重复的HTML块 标记帮助器使它看起来很简单: <vc:expansion-panel title="Headline"> content..... </vc:expansion-panel> ExpansionPanelViewComponent.cs using Microsoft.AspNetCore.Mvc; namespace ProjectName.Component
<vc:expansion-panel title="Headline">
content.....
</vc:expansion-panel>
ExpansionPanelViewComponent.cs
using Microsoft.AspNetCore.Mvc;
namespace ProjectName.Components
{
public class ExpansionPanelViewComponent : ViewComponent
{
public IViewComponentResult Invoke(string title)
{
ViewData["Title"] = title;
return View();
}
}
}
Default.cshtml
<h2 class="panel">@ViewData["Title"]</h2>
<div class="panel">
@RenderBody() <----- ??
</div>
@ViewData[“Title”]
@RenderBody()@RenderBody调用的可能副本指定视图内容在布局中的显示位置。你不能在其他任何地方使用它。重复?对但这个问题没有得到回答。OP将其标记为已回答,只是因为他找到了解决方法。您要呈现的是在默认页面上显示标记帮助器中的内容?好吧,这不太可能。默认页面中的内容将覆盖标记帮助器的内容。除非内容用作上面链接中提到的标记帮助器的参数
<h2 class="panel">@ViewData["Title"]</h2>
<div class="panel">
@RenderBody() <----- ??
</div>