.net core 如何以renderSection结果为参数从Layout调用ViewComponent

问题描述

因为我必须使用依赖注入,所以我的网站标题使用布局页面中的视图组件呈现。

现在我需要在这标题添加一个部分,该部分应该在继承该布局但找不到如何设置的页面中设置

布局

<header>
    @await Component.InvokeAsync("Intestazione",new {paginaGuida = RenderSection("PaginaCorrente",required : false).Value })
</header>

组件

public async Task<IViewComponentResult> InvokeAsync(bool utente= true,string paginaGuida = null)
    {
        Intestazioneviewmodel vm = null;
        if (paginaGuida is not null && utente) { 
            vm = new Intestazioneviewmodel($"?paginaCorrente={paginaGuida}",await gestioneUtenza.GetUtenteCorrente());            
            return View(vm);
        }
        else
        {
            return View("SenzaUtente");
        }
    }

viewComponent 视图

<a id="help" class="far btn-menu-guida" title="Help" href="@("~/Guida" + Model.UrlGuida)">
        <span>Help</span>
    </a>

示例页面

@section PaginaCorrente {@((int)PaginaCorrenteGuidaEnum.Dettaglio)}

调用viewcomponent时paginaGuida参数始终为空,而在示例页面中section写入的文本为数字

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...