在MVC属性控制器路由上的多个路径prefixe? [英] Multiple RoutePrefixe on a controller in MVC Attribute routing?

查看:311
本文介绍了在MVC属性控制器路由上的多个路径prefixe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的MVC属性的路由我知道你可以指定多个路线属性一个的ActionResult ,但我寻找一种方式做在路线preFIX 的水平不变。我有一个控制器,它的每一个动作应该由3条路线可访问:

In the new MVC Attribute Routing I know you can assign multiple Route attributes to a single ActionResult but I am looking for a way to do the same at the RoutePrefix level. I have a controller that every action in it should be accessible by 3 routes:

/游戏/ {标题} /字符/ {}路线
/书籍/ {标题} /字符/ {}路线
/影院/ {标题} /字符/ {路线}

我试图把三(3)路线preFIX 命令,但得到的错误 Deuplace路线preFIX属性。如果我尝试使用逗号分隔的列表,我得到为不包含一个构造函数3个参数的最佳覆盖方法

I tried putting three (3) RoutePrefix commands but get the error Deuplace RoutePrefix attribute. If I try to use a comma separated list I get Best override method for does not contain a constructor that takes 3 arguments.

是否有可能设置一个路由preFIX因此,它需要的3路我要为我的控制器?

Is it possible to setup a RoutePrefix so that it takes the 3 routes I want for my controller?

推荐答案

运行一系列测试,我发现,我可以再补充3 路线属性控制器级别和它的作品就是我想要的。

Running a bunch of tests I found out that I can just add 3 Route attributes to the controller level and it works the way I want.

编辑:更好的方法来做到这一点,我发现是使用正则表达式匹配方法

a better way to do it I found was using the regex match method

[路线preFIX({类型:正则表达式(游戏|电影|书籍)} / {SectionRoute} /字符/)]

这篇关于在MVC属性控制器路由上的多个路径prefixe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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