ASP MVC 路由
现在这可能是一个愚蠢的问题,但我是 mvc 新手,似乎无法让它工作。
这是我希望能够对网址/路线执行的操作:
1)www.domain.com/name/home/index
2) www.domain.com/home/index
其中两个主控制器都是单独的控制器,名称部分将非常但全部必须转到同一个控制器,并且名称应该是其中所有操作的参数。
这有可能吗?感谢您的帮助。
now this is probably an stupid question but i'm new to mvc and can't seem to get it working.
Here is what i would like to be able to do with the urls/routes:
1) www.domain.com/name/home/index
2) www.domain.com/home/index
where both the home controllers are seperate controllers and the name part will very but all must go to the same controller and the name should be an param for all the actions in there.
Is this at all possible? Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能不是您正在寻找的答案,但我认为更常见的是看到
我最初的想法是重载的
Index
操作方法是有意义的,但是 丹尼尔指出这是不允许的(至少不是以我建议的方式)。更新的答案...
您的
Index
操作方法可以采用string name
参数,并且您的路由需要包含类似在您的操作方法中的快速
null< /code> 检查会告诉您 URL 中是否包含
name
。This might not be the answer you're looking for, but I think that it would be more usual to see
My initial thinking was that an overloaded
Index
action method would make sense, but Daniel pointed out that this not allowed (at least not in the manner I suggested).Updated answer...
Your
Index
action method could take astring name
argument, and your routes would need to contain something likeIn your action method a quick
null
check will tell you whether aname
was included in the URL or not.