简体   繁体   English

Asp.Net核心使用Html.ActionLink路由到区域控制器

[英]Asp.Net Core Routing to an area controller with Html.ActionLink

I have my routing setup in Startup.cs like this 我在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?}");

        });

and a controller configured like this: 和一个像这样配置的控制器:

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

on my home page I have a link setup to go to this controller: 在我的主页上,我有一个链接设置转到此控制器:

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

only this renders the link as 只有这样才能将链接呈现为

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

when the actual url for the controller seems to be 当控制器的实际网址似乎是

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

I don't understand how this is worked out and where the extra "Pad" in the url is coming from. 我不明白这是如何解决的,以及网址中额外的“垫”来自何处。 Can anyone enlighten me. 任何人都可以启发我。

Incase anyone else comes across this weirdness, I managed to solve this by creating a new project and adding all the code into it bit by it. 如果其他人遇到这种奇怪的事情,我设法通过创建一个新项目并将所有代码添加到其中来解决这个问题。 I thought this would help me identify the problem, instead it just went away! 我认为这可以帮助我找出问题,而不是它就消失了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM