在 asp.net 核心中生成动态路由路径
Generate dynamic route path in asp.net core
我创建了一个 .net 核心应用程序,它具有以下 crud 操作路径。
创建:http://localhost:1001/admin/123/app/456/user/Create
更新:http://localhost:1001/admin/123/app/456/user/Update
Select: http://localhost:1001/admin/123/app/456/user/Select
写在下面将解决 URL 中的问题。
routes.MapRoute("CreateUser", "apps/{appId}/user/create",
defaults: new { controller = "User", action = "Create" });
如何在 .cshtml 文件中包含相同的内容,即
<a asp-action="Create" asp-controller="User"> Create User </a>
感谢您的快速帮助。
您可以使用 asp-route-{value}
选项在锚标记助手中指示路由值:
<a asp-action="Create" asp-controller="User" asp-route-adminID="@Model.AdminId" asp-route-appId="@Model.AppId"> Create User </a>
请注意,我假设页面模型中提供了 adminId
和 appId
值。如果错误,请设置适当的变量而不是代码中的变量。
我创建了一个 .net 核心应用程序,它具有以下 crud 操作路径。
创建:http://localhost:1001/admin/123/app/456/user/Create
更新:http://localhost:1001/admin/123/app/456/user/Update
Select: http://localhost:1001/admin/123/app/456/user/Select
写在下面将解决 URL 中的问题。
routes.MapRoute("CreateUser", "apps/{appId}/user/create",
defaults: new { controller = "User", action = "Create" });
如何在 .cshtml 文件中包含相同的内容,即
<a asp-action="Create" asp-controller="User"> Create User </a>
感谢您的快速帮助。
您可以使用 asp-route-{value}
选项在锚标记助手中指示路由值:
<a asp-action="Create" asp-controller="User" asp-route-adminID="@Model.AdminId" asp-route-appId="@Model.AppId"> Create User </a>
请注意,我假设页面模型中提供了 adminId
和 appId
值。如果错误,请设置适当的变量而不是代码中的变量。