mvc 路由 - 将数据从路由传递到显示控制器

发布于 2024-12-07 21:01:52 字数 213 浏览 0 评论 0原文

我有一条如下所示的路线:

/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场信仰旅途 2024-12-14 21:01:53

基于我问的另一个问题 MVC3 路由 - 相互构建的路由

解决方案是正确命名我的路线,每个 id 都有一个唯一的名称。
公司为 CompanyId,联系人为 ContactId。

/Company/{CompnayId}/Contact/{ContactId}

然后在控制器方法中签名可能如下所示:

ActionView Edit(int CompanyId, int 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.

/Company/{CompnayId}/Contact/{ContactId}

Then in the controller method the signature could look like:

ActionView Edit(int CompanyId, int ContactId))
{
...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文