mvc 路由 - 将数据从路由传递到显示控制器
我有一条如下所示的路线:
/Company/1234/Contact/3456
我的路线的一般模式是字符串是操作/区域,数字是记录 ID。
在联系人控制器(操作{编辑})中,我想传入公司和联系人的 ID。 框架中有没有办法获取这些信息?或者我是否需要解析路线中的所有数值才能知道哪个是什么?
任何帮助都会很棒。
I have a route like the following:
/Company/1234/Contact/3456
The general pattern for my routes is that strings are actions/areas and numerics are the records ids.
In the Contact controller (action{edit}) I want to pass in the id from the company and the contact.
Is there a way in the framework to get that information? Or do I need to parse all numeric values in the route in order to know which is what?
Any help would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于我问的另一个问题 MVC3 路由 - 相互构建的路由
解决方案是正确命名我的路线,每个 id 都有一个唯一的名称。
公司为 CompanyId,联系人为 ContactId。
然后在控制器方法中签名可能如下所示:
Based on an other question I asked MVC3 Routing - Routes that builds on each other
The solution would be to name my routes correctly, with each id having a unique name.
Company would be CompanyId, contact would be ContactId.
Then in the controller method the signature could look like: