从URL MVC忽略控制器名称 [英] Omit controller name from URL mvc
问题描述
我希望做类似这样的帖子的内容:
<一个href=\"http://stackoverflow.com/questions/380221/how-to-hide-controller-name-in-url\">http://stackoverflow.com/questions/380221/how-to-hide-controller-name-in-url
不作任何种类的ID。
服务器正在运行IIS 6和页面已经显示没有扩展名的,所以它不是一个通配符问题。
我在找打 http://website.com/action-name
我有 http://website.com/controller/action-name 工作
我假定这只是,我莫名其妙地消磨了一个简单的路由变化。我当前的路由规则是:
routes.MapRoute(
RouteName
{行动},
新{控制器=家,行动=索引}
);
是您新的路由规则定位的 的的默认路由规则{控制器,动作ID}上面
,使其有机会匹配的第一个的?
I'm looking to do something similar to this post:
http://stackoverflow.com/questions/380221/how-to-hide-controller-name-in-url
only without any sort of ID.
The server is running IIS 6 and the pages already show up without extensions so it's not a wildcard issue.
I'm looking to hit http://website.com/action-name
I have http://website.com/controller/action-name working
I'm assuming this is just a simple routing change that I am somehow goofing up. My current routing rule is:
routes.MapRoute(
"RouteName",
"{action}",
new { controller = "Home", action = "Index" }
);
Is your new routing rule positioned above the default routing rule of {controller, action, id}
so that it has the opportunity to match first?
这篇关于从URL MVC忽略控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!