首页 > 解决方案 > 迁移到 asp.net 核心时用 taghelper 替换 @helper

问题描述

在我的应用程序框架的当前版本中,我有一个 Razor HTML @helper,如下所示:

@helper SideMenuItem(string display, string action, string controller, string area, string faIcon)
{
    <li class="@Html.IsSelected(controller, action)">
        <a href="@Url.Action(action, controller, new {area})"><i class="fa @faIcon"></i> <span class="nav-label">@display</span> </a>
    </li>
}

据我所知,这种语法格式已在 asp.net 核心中删除,现在首选方法是通过tag helpers。但是,我很难理解 asp.net 核心中的等价物是什么。我现在需要声明一个完整的类来获得与旧@helper类相同的重用水平,这似乎很奇怪。我错过了什么吗?

标签: c#razorasp.net-coreasp.net-core-tag-helpers

解决方案


推荐阅读