如何在这种情况下在 ASP.NET MVC 应用程序中构造视图/控制器/操作(/区域?)?

发布于 2024-09-17 18:52:18 字数 731 浏览 1 评论 0原文

alt text

顶部有一些关于 foo 的最有用的信息。

在水平线之间有一些立即操作(如果可用)可以在 foo 上执行/与 foo 一起执行。

下面是困扰我的事情。这里有关于 foo 的选项卡式详细信息。
这些选项卡也可以保存一些操作,并且可以非常独立。

所以问题是 - 如何正确构建这个东西(控制器、动作应该是什么,它们如何相互交谈)以避免不必要的麻烦?

我很困惑,因为下面的这些选项卡就像一个单独的岛屿。


在模型中 - 有一个奇怪的事情:一对一的关系。就像有一个竞赛 (Foo) 和参与者。选项卡是参与者的详细描述。

目前,我已将它们建模为聚合根。但这可能是一个错误的选择。

因此,如果有两个根,那么它们都有控制器,并且 Contest 并不真正负责保存所有数据,这似乎是很自然的。

看来子操作是可行的方法,但我预见到会有些复杂。当选项卡包含某些操作时,他们需要知道如何重定向回“竞赛”详细信息以及如何传递如何呈现正确选项卡的信息。我想避免这种耦合,但似乎没有办法做到这一点。

alt text

At top there is some most useful info about foo.

Between horizontal lines there is some immediate actions, if they are available, to perform on/with foo.

And below is thing that bothers me. There goes tabbed, detailed information about foo.
Those tabs can hold some actions too and can be quite sovereign.

So the question is - how to properly structure this thing (what should be controllers, actions, how do they talk to each other) in order to avoid unnecessary hussle?

I'm confused cause those tabs below are like a separate island.


In model - there's that strange thing: 1 on 1 relation. It's like there's a Contest (Foo), and Participant. Tabs are detailed description of Participant.

Currently I've modeled them both as aggregate roots. But it might be a wrong choice.

So - if there are two roots, it seems natural if both of them got controllers and Contest isn't really responsible to hold all data.

It seems that sub actions would be the way to go, but I foresee some complexity. When tabs will hold some actions, they will need to know how to redirect back to Contest details and how to pass info how to render correct tab. This coupling I would like to avoid but it seems there's no way to do that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

别把无礼当个性 2024-09-24 18:52:18

我可以为这些选项卡想到几个选项……哪一个有意义可能取决于您的模型的外观、检索数据的方式以及在某种程度上,应用程序的其余部分的外观。

选项 1。使用 RenderPartial() 的部分视图。每个选项卡都是一个局部视图,用于呈现模型的某些部分。例如,您将有一个呈现 Model.FinancialInformation 的 FinancialInformation.aspx 部分视图。

选项 2a。使用 RenderAction() 的子操作。与上面类似,只是每个选项卡负责通过调用同一控制器或更可能是专门处理该信息的另一个控制器上的操作方法来拉取自己的数据。

选项 2b。与 2a 相同,只是选项卡是使用 AJAX 按需呈现的。

我应该指出,这些选项都不是相互排斥的。您可以对前两个选项卡使用选项 1 (RenderPartial()),因为该数据本质上是模型的一部分。您可以将选项 2 (RenderAction()) 用于其他两个选项卡,因为例如您可能有一个专门渲染图表的 ChartController ...

I can think of a couple options for those tabs ... which one makes sense probably depends on what your Model looks like, how you retrieve data and, to some degree, what the rest of your app looks like.

Option 1. Partial Views with RenderPartial(). Each tab is a partial view that renders some portion of your Model. For example, you would have a FinancialInformation.aspx partial view that renders Model.FinancialInformation.

Option 2a. Sub Actions with RenderAction(). Similar to above except that each tab is responsible for pulling its own data by calling an action method either on the same controller or more likely another controller that specializes in that information.

Option 2b. Same as 2a except that the tabs are rendered on demand using AJAX.

I should point out that none of these options is mutually exclusive. You might use option 1 (RenderPartial()) for the first two tabs since that data is inherently part of your model. And you might use option 2 (RenderAction()) for the other two tabs because, for example, you might have a ChartController the specializes in rendering charts ...

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