NerdDinner 中的课程安排

发布于 2024-10-19 12:25:16 字数 368 浏览 2 评论 0原文

我正在学习 ASP.NET MVC 并查看 ASP.NET MVC 示例应用程序 NerdDinner

  1. 文件夹“Models”包含一个名为Dinner.cs的类。这是主要的晚餐实体。 这堂课不应该在其他地方吗?例如“域”?相反,应该将视图模型类放入包含晚餐信息的 Models 文件夹中吗?

  2. 为什么文件“PaginatedList.cs”位于名为“Helpers”的文件夹中。由于该文件是提供给视图的,所以它不应该位于“Models”文件夹中吗?

对此的任何澄清将不胜感激!

I am learning ASP.NET MVC and looking at the ASP.NET MVC sample application NerdDinner.

  1. The folder "Models" contains a class called Dinner.cs. This is the main Dinner entity.
    Shouldn't this class be in an other location? For example "Domain" ? And instead should a viewmodel class be put in the Models folder that contains dinner information?

  2. Why is the file "PaginatedList.cs" located in the folder called: "Helpers". Shouldn't this file be in the folder: "Models" since it is supplied to views?

Any clearification on this would realy be appreciated!

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

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

发布评论

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

评论(2

溇涏 2024-10-26 12:25:17
  1. 当然,您的想法是正确的。 NerdDinner 的制作只是为了概念演示的目的,并没有真正假装所有的最佳实践。随着你自己的项目的成长,它会变得越来越明显。您将把域实体/服务/存储库放在单独的文件夹中,然后是单独的项目,然后可能是单独的解决方案。您会发现自己将此文件夹重命名为 ViewModels,以使其对于从事项目的其他人来说更加明显。

  2. PaginatedList 可以是 ViewModel 并包含与分页相关的数据。然后可以将其放入 ViewModels 文件夹中。但我相信 NerdDinner 中的内容只是一个简单的视图助手来生成分页标记。此外,助手可能不是那么严格的“View”或“ViewModel”——它们可以包含简单的逻辑,它们在某种程度上处于 View 和 ViewModel 之间的中间:)。另请注意,PaginatedList 更多的是“框架”问题,而不是“特定解决方案”。因此,您不能将其放置在项目特定内容中的“Views”或“Models”文件夹中。所以“Helpers”对于 NerdDinner 来说已经足够了。在真正的解决方案中,您最好使其通用,将其包含到 MVC 之上的“框架”中。

  1. Sure, your thinking is right about this. NerdDinner is made just for concept-presentation purposes and doesn't really pretends to all the best practices. It becomes more and more obvious as your own project grows. You will have your domain entities/services/repositories in separate folder, then separate project, then possibly separate solution. You will find yourself renamed this folder to ViewModels to make it more obvious for other people working on project.

  2. PaginatedList can be a ViewModel and contain data related to pagination. Then it can be put to ViewModels folder. But I believe what you have in NerdDinner - is just a simple View helper to generate pagination markup. Moreover, helpers could be not that strict "View" or "ViewModel" - they can contain simple logic, they're somewhat in the middle :) between View and ViewModel. Also note that PaginatedList is more of a "framework" concern than of a "particular solution". So you can't place it to "Views" or "Models" folder amongst project-specific things. So "Helpers" is good enough for NerdDinner. In a real solution you'd better make it common, include it into your "framework" that is on top of MVC.

苦笑流年记忆 2024-10-26 12:25:17

对于第一个问题,Dinner.cs 文件包含部分 Dinner 类以及好友类的一些验证属性。恕我直言,将此文件放入 Model 文件夹中是完全明智的,因为它实际上是解决方案模型的一部分。

对于第二个问题,PaginatedList 是一种数据结构,它允许您一次查看数据的某个“页面”(一组固定的元素)。我真的不认为它是一个ViewModel,它就是一个“助手”。

我还想补充的一件事是,如果您有一些 ViewModel 传递到视图中而不是实际的模型类,或者因为您有一组特定的数据元素要传递,我认为这是合理的一个单独的 ViewModel 文件夹。

希望这有帮助:)

for the first question, the Dinner.cs file contains a partial of the Dinner class along with some validation attributes on a buddy class. It's perfectly sane, IMHO, to put this file into the Model folder, since it's actually part of the solution's model.

for your second question, the PaginatedList is kind of a data structure which allows you to view a certain "page" of your data (a fixed set of elements) at a time. I don't really see it being a ViewModel, a "helper" is exactly what it is.

One more thing I would like to add is, if you have some ViewModels that you pass in to your views instead of the actual model classes, or because you have a specific set of data elements to pass, I think it would be reasonable to have a separate ViewModel folder for that.

Hope this helps :)

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