Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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页TagHelper时未呈现链接_C#_Asp.net Core 2.0_Razor Pages_Asp.net Core Tag Helpers - Fatal编程技术网

C# 使用asp页TagHelper时未呈现链接

C# 使用asp页TagHelper时未呈现链接,c#,asp.net-core-2.0,razor-pages,asp.net-core-tag-helpers,C#,Asp.net Core 2.0,Razor Pages,Asp.net Core Tag Helpers,我有一个页面在使用asp页面时不以HTML呈现链接。我以前见过这种情况,但这是由于打字错误或网页不存在 在下面的_布局中的两个链接中 用户呈现为http://localhost/ReportGroups/Admin/Users 角色呈现为http://localhost/ReportGroups 手动导航到角色会导致404错误 \u Layout.cshtml @page "{roleId}/{userId}" @model RoleListModel @{ ViewData["Pa

我有一个页面在使用asp页面时不以HTML呈现链接。我以前见过这种情况,但这是由于打字错误或网页不存在

在下面的_布局中的两个链接中

  • 用户呈现为
    http://localhost/ReportGroups/Admin/Users
  • 角色呈现为
    http://localhost/ReportGroups
  • 手动导航到角色会导致404错误
\u Layout.cshtml

@page "{roleId}/{userId}"
@model RoleListModel
@{
    ViewData["PageTitle"] = "Admin Tools - Roles";
    ViewData["IconClass"] = "";
    ViewData["IconTitle"] = "Roles";
}

<table>
    <thead>
        <tr>
            <th>Role</th>
            <th>User Name</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        @foreach (ApplicationRole role in Model.AppRoles)
        {

            <tr>
                <td colspan="4"><strong>@role.Name</strong></td>
                <td>
                    <a asp-page="/App/RoleEdit" asp-route-roleId="@role.Id"><i class="fas fa-edit"></i></a>
                </td>
            </tr>

            IList<ApplicationUser> usersOfRole = Model.AppRoleUsersDict[role];
            foreach (ApplicationUser user in usersOfRole)
            {
                <tr>
                    <td>@role.Name</td>
                    <td>@user.UserName</td>
                    <td>@user.FirstName</td>
                    <td>@user.LastName</td>
                    <td>
                        <form method="post" asp-page-handler="delete">
                            <button type="submit" asp-page="/App/GroupEdit" asp-page-handler="delete" asp-route-roleId="@role.Id" asp-route-userId="@user.Id">
                                <i class="fas fa-trash-alt" style="color:red"></i>
                            </button>
                        </form>
                    </td>
                </tr>
            }
        }

    </tbody>
</table>
@using Microsoft.AspNetCore.Identity
@using CtrackReportGroupsRtca
@using Ctrack.ReportGroups.Data
@using Ctrack.ReportGroups.Identity
@using System.Security.Claims
@using Microsoft.AspNetCore.Html;
@namespace Ctrack.ReportGroups.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
该链接是管理菜单的一部分。注释掉的图标是我测试的一部分
/Admin/Users
工作正常,但
/Admin/RoleList
不工作。它以前是
/Admin/Roles
,但是我构建了一个新的文件副本,以查看是否有任何东西抛出错误,或者它是否是一个保留字

@if (User.Identity.IsAuthenticated)
{
    if (User.IsInRole("Admin"))
    {
        <div id="nav-admin">
            <ul>
                <li><a asp-page="/Admin/Users"> Users</a></li>@*< i class="fas fa-user-secret" title="Users"></i>*@
                <li><a asp-page="/Admin/RoleList"> Roles</a></li>
                @*<i class="fas fa-id-card" title="Roles"></i>*@
            </ul>
        </div>
    }
}

它不起作用的原因是您没有定义roleId和userId值。将链接更改为以下内容:

<a asp-page="/Admin/RoleList" asp-route-roleId="YourRoleID" asp-route-userId="YourUserID"> Roles</a>
角色

我正在使用.NET Core 2.2,遇到了类似的问题。我用电脑把它修好了

asp-page="/ThePage/Index"
而不是

asp-page="/ThePage"

但这可能掩盖了另一个根本问题。

在我的情况下,我忘记在页面顶部包含
@page
指令:

@page

<h1>Hello, world!</h1>
@page
你好,世界!

将此代码包含在当前的_ViewImports.cshtml中,为我解决


@addTagHelper*,Microsoft.AspNetCore.Mvc.TagHelpers

奇怪的是,我必须定义它(使用无效值)并且它可以工作。而不是不定义它。哦,好吧。谢谢你的帮助:)这也解决了我的问题。这也解决了我的问题。根据这里的评论:这似乎是出于设计。
@page

<h1>Hello, world!</h1>