Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP MVC核心:ViewComponent内部HTML_C#_.net_Asp.net Core - Fatal编程技术网

C# ASP MVC核心:ViewComponent内部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

我正在尝试使用ViewComponents在ASP MVC Core 2.1中封装重复的HTML块

标记帮助器使它看起来很简单:

<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>