路由:如何网址隐藏行动的名字吗? [英] Routing: How to hide action name in url?
问题描述
在MVC默认路由
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
每当index动作被访问时,URL没有显示当指数行动被访问的动作名称。
whenever the index action is accessed, the url is not showing the action name when the "Index" action is accessed.
我想获得一个不同的控制器,这是一个单一的项目获取数据上的行为。我希望被命名的默认操作的get这个动作,我想的网址不显示操作名称,只是控制器和项ID。
I would like to get that behaviour on a different controller, which is retrieving data for a single item. I would like the default action to be named "get" and for this action I would like the url not to display the action name, just the controller and the item id.
我想,类似的路线上面的人,像这样的:
I thought that a similar route to the one above, like this:
routes.MapRoute(
"item_details",
"item/{action}/{id}",
new { controller = "item", action = "Get" }
);
会做的伎俩,但它给我像本地主机地址:XXXX /项目/ GET / 152 ...我缺少什么
would do the trick, but it gives me a url like localhost:xxxx/item/Get/152... What am I missing?
推荐答案
试试这个:
routes.MapRoute(
"item_details",
"item/{id}",
new { controller = "item", action = "Get" }
);
这篇关于路由:如何网址隐藏行动的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!