且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC路由与默认的控制器

更新时间:2023-02-15 21:45:05

不要混用如下规则:一个{行动} / {ID}这是{控制器} / {行动} / {ID} ...特别是当ID在以后有默认值即是可选的。

don't mix a rule like: "{action}/{id}" with one that's "{controller}/{action}/{id}" ... specially when id in the later has a default value i.e. is optional.

在你有什么这种情况下,允许路由知道哪一个是要使用的正确的。

In that case you have nothing that allows routing to know which one is the right one to use.

有一个解决办法,如果这是你所需要的,将是增加一个约束(见this)在更早的一组值,即表,视图的作用。当然,与这些类型的规则,你不能有一个动作的名称相同的控制器。

A workaround, if that's what you need, would be to add a constrain (see this) to the action in the earlier to a set of values i.e. List, View. Of course that with these types of rules, you can't have a controller with the same name of an action.

还要记住,如果你指定一个默认的行为和放大器; ID在当你打你的站点的路径将被用于{}动作/(编号)规则。

Also remember that if you specify a default action & id in the "{action}/{id}" rule, that will be used when you hit the route of your site.