Html ActionLink Route problem

独自空忆成欢 提交于 2019-12-12 01:20:01

问题


i have defined the following Routes:

routes.MapRoute("Blog",
            "Blog/{controller}/{action}",
            new { controller = "Test", action = "Index" });

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

When i call http://localhost/ all Links are wrong and go to the Blog:

@Html.ActionLink("About", "About", "Home") creates the following URL:

localhost/Blog/About

but it should create

localhost/About

Why does HtmlActionLink always prefix the urls with the "Blog"?


回答1:


ActionLink will the first route that matches the parameters you passed to it.
Since your Blog route contains the controller and action parameters, it will use that route.

You should change your Blog route to be more specific.



来源:https://stackoverflow.com/questions/4923107/html-actionlink-route-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!