0

我有这个路由图:

routes.MapRoute(
            "ViewNews",
            "{controller}/{action}/{id}/{title}",
            new { controller = "Home", action = "NewsDetail", id = "", title = "" }
        );

在我看来这个 ActionLink :

@Html.ActionLink(Model.Title, "NewsDetail", new { id = Model.Id, title = Url.ToFriendlyUrl(Model.Title) })

我希望它呈现如下内容:

http://localhost:49327/Home/NewsDetail/1/news-title

相反,它呈现:

http://localhost:49327/Home/NewsDetail/1?title=news-title

我想念什么?

更新

我以这种方式在默认之前移动了 MapRoute:

routes.MapRoute(
        "ViewNews",
        "{controller}/{action}/{id}/{title}",
        new { controller = "Home", action = "NewsDetail", id = "", title = "" }
        );


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

        );

但现在当我请求初始 URL 时:

http://localhost:49327/Home

我立即被重定向到:

http://localhost:49327/Home/NewsDetail/1/news-title

“NewsDetail”已成为默认操作!

在此处输入图像描述

4

1 回答 1

1

确保Model.Id参数不为空或不为空,并且默认路由不在您在 Global.asax 中显示的路由之前。您需要将其删除或放置在此自定义路线之后。

于 2012-09-26T11:01:05.623 回答