【问题标题】:Asp.Net Core Routing to an area controller with Html.ActionLinkAsp.Net Core 使用 Html.ActionLink 路由到区域控制器
【发布时间】:2019-03-22 10:18:42
【问题描述】:

我在 Startup.cs 中有这样的路由设置

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "areas",
                template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

          routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

        });

和这样配置的控制器:

[Area("Pad")]
public class RequestsController : BaseController
{
    [HttpGet]
    public ActionResult Index()
    {
   ....
     }
}

在我的主页上,我有一个链接设置到这个控制器:

 @Html.ActionLink("PAD","Index","Requests",new{area="Pad"},null)

只有这会将链接呈现为

<a href="/Pad/Requests">PAD</a>

当控制器的实际 url 似乎是

https://localhost:44358/Pad/Pad/Requests

我不明白这是如何解决的,以及 url 中额外的“Pad”是从哪里来的。谁能赐教。

【问题讨论】:

  • 你从哪里得到这个链接/Pad/Pad/RequestsActionLink渲染的那个是对的
  • when the actual url for the controller seems to be 是什么意思?与我们分享一个可以重现您的问题的演示。
  • @Alexander - 我相信操作链接呈现的那个也是正确的..但它给出了 404 错误, /Pad/Pad/Requests 是实际工作的那个

标签: c# asp.net-core routing


【解决方案1】:

如果其他人遇到这种奇怪的情况,我设法通过创建一个新项目并将所有代码添加到其中来解决这个问题。我认为这可以帮助我找出问题所在,结果它就消失了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 2021-05-04
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多