简体   繁体   中英

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

I have my routing setup in Startup.cs like this

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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