开发者

mvc routing - Passing data to a display controller from the Route

开发者 https://www.devze.com 2023-04-10 20:08 出处:网络
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.

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 in开发者_运维百科formation? Or do I need to parse all numeric values in the route in order to know which is what?

Any help would be great.


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))
{
...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号