I'm trying to wrap up repeating HTML chunks in ASP MVC Core 2.1 using ViewComponents.
Tag helpers make it seemingly easy:
<vc:expansion-panel title="Headline">
content.....
</vc:expansion-panel>
However: The inner HTML of the tag is not rendered. RenderBody()
obviously is not the appropriate function here. So what function should be used?
Since I haven't found any references online, probably I got the wrong idea about ViewComponents. However, even if so, I would still see no reason why not to render inner HTML into the ViewComponent
.
Qestion: How to render the Inner HTML of <vc:expansion-panel>...
in the ViewComponent
?
@addTagHelper *, ProjectName
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>