首页 新闻 会员 周边 捐助

mvc中的路由

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-03-25 15:34

想实现这种链接:

www.xxxx.com/news/1015.html

用这两种方法,都实现不了

Html.ActionLink()
Url.Action()

这两种方法,都会生成

/?id=1015

所以只能手动拼接链接地址了,但手动拼接的话,不能指定

new {area="xxx"}

不能指定导致,网站的路由乱了

比如,正常下请求:

www.xxxx.com/news/1015.html 正确

login.xxxx.com/news/1015.html 也能正确请求,

以下是三个路由:

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new
                {
                    controller = "Home",
                    action = "Index",
                    id = UrlParameter.Optional
                },
                namespaces: new string[] { "NoahHotel.Extensions.Controllers.WebSite" }
                );

 

routes.Add("NoahHotel__Domain_Login", new DomainRoute(
                "login.noahhotel.cn",
                "{controller}/{action}/{id}",
                new
                {
                    area = "Login",
                    controller = "Home",
                    action = "Login",
                    id = UrlParameter.Optional,
                    Namespaces = new string[] { "NoahHotel.Extensions.Controllers.Login" }
                }
                ));

 

context.MapRoute(
                "Category",
                "Category/{Action}/{CategoryId}.html",
                new
                {
                    controller="Category",
                    action="Info",
                    CategoryId=@"(\d)+"
                },
                null,
                new string[] { "NoahHotel.Extensions.Controllers.WebSite" }
                );

 

是哪里出问题了吗?

king2003的主页 king2003 | 初学一级 | 园豆:161
提问于:2014-03-21 16:30
< >
分享
所有回答(1)
0

自定义路由写在默认路由上面试试。asp.net mvc 的路由匹配机制是先到显得的

向晚 | 园豆:79 (初学一级) | 2014-03-23 16:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册