如何/动作/ ID映射到正义行动/ ID? [英] How to map Home/Action/id to just action/id?

查看:80
本文介绍了如何/动作/ ID映射到正义行动/ ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我刚才定义的这条路线

At the moment I have just this route defined

 routes.MapRoute(
                "Default",                                                
                "{controller}/{action}/{id}",                           
                new { controller = "Home", action = "Index", id = "" } 
                );

我要地图到/ home /措施1 / ID只/措施1 / ID
任何人都知道如何?

I want to map the /Home/Action1/id to just /Action1/id anybody knows how ?

推荐答案

您可能会像你要求的,因为它可以捕获超过拟小心的路线。

You may have to be careful with a route like you're asking for because it may catch more than is intended.

一个解决办法是通过可能的话使用约束来限制这条路线。

One workaround is to restrict that route by using constraints if possible.

例如。检查id是数字...

E.g. Check that id is numeric...

routes.MapRoute("ActionRoute", 
         "{action}/{id}",
         new { controller = "Home", action = "Index", id="1" },
         new { id = @"\d{1,6}" }
);

您仍然可以在最后指定通用默认路由的方式来捕捉路线的其余部分,如果需要在网站上。

That way you can still specify your generic default route at the end to catch the rest of the routes on the site if needed.

这篇关于如何/动作/ ID映射到正义行动/ ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆