开发者

ASP.NET MVC 2 Controllers to Model Associations

In my model I have relationships like this:

[Person]
 PersonId (PK)
 ...

[Orders]
 OrderId (PK)
 PersonId (FK to Person.PersonId)
 ...

A person can have multiple orders.

I generated PersonController with Create/Details/List/Edit views. I want to be able to manipulate Orders also, but within the context of a Person. In other words, I'd like the workflow to be

  • User browses a list of people (/Persons)
  • User selects 'View Orders' link next to a specific Person (/Persons/4/Orders/)
  • User sees a list of orders with Create/Details/Edit a开发者_Go百科s well (/Persons/4/Orders/Edit/38)

Is this the right way to set up my controllers/routes? Should I just access orders at routes like (/Orders/Edit/38) instead?

Right now I have:

PersonController OrderController

Should I create a PersonOrderController or can I achieve what I want using only the two controllers I already have?


You should probably use just the two Controllers you already have. It is a judgment call however. Two different excellent MVC designers might do this two different ways. Unless you already see a lot of other work for your OrderController, you should start with two controllers. If OrderController becomes bloated, you can refactor.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜