任何方法来创建一个包罗万象的路线

编程入门 行业动态 更新时间:2024-10-10 07:25:44
本文介绍了任何方法来创建一个包罗万象的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个控制器上的许多行动

I have many actions on a controller

Controller1\Action1 Controller1\Action2 Controller1\Action3 Controller1\Action4 Controller1\Action5 Controller1\Action6

我想我的网址永远只是:

I would like my URLs to always be just:

Action1 Action2 Action3 Action4 Action5 Action6

有没有一种简单的方法来做到这一点?我不会有任何冲突,其中:

Is there an easy way to do this? I won't have any conflicts where:

Controller1\Action1 Controller2\Action1

每一个动作都会有一个唯一的名称。

Every action will have a unique name.

推荐答案

您应该能够做这样的事:

You should be able to do something like this:

routes.MapRoute( "CatchAll", "{action}/{*path}", new { controller = "MyController", action = "Index" } );

基本上你告诉它所有的请求应该将路径作为行动和他们都应该去myController的。行动=指数作为该操作未在URL中提供的事件的缺省值。

Essentially you're telling it all requests should treat the path as the Action and they should all go to "MyController". The action = "Index" acts as a default in the event that an Action is not provided in the Url.

上面的路由定义将评估为真,即使额外的,无效的路径数据动作名称后面。这也就意味着,无论 /措施1 和 /措施1 / 251958125ad / 2512qsadfa2 将前往措施1()。如果您想preFER只有确切路径被允许的:

The above route definition will evaluate to true even if extra, invalid path data is appended after the action name. What that means is that both /Action1 and /Action1/251958125ad/2512qsadfa2 will go to Action1(). If you would prefer that only the exact path be allowed:

routes.MapRoute( "CatchAll", "{action}", new { controller = "MyController", action = "Index" } );

更多推荐

任何方法来创建一个包罗万象的路线

本文发布于:2023-11-28 08:47:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641727.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:包罗万象   方法来   创建一个   路线

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!