NerdDinner 中的课程安排
我正在学习 ASP.NET MVC 并查看 ASP.NET MVC 示例应用程序 NerdDinner。
文件夹“Models”包含一个名为
Dinner.cs
的类。这是主要的晚餐实体。 这堂课不应该在其他地方吗?例如“域”?相反,应该将视图模型类放入包含晚餐信息的 Models 文件夹中吗?为什么文件“PaginatedList.cs”位于名为“Helpers”的文件夹中。由于该文件是提供给视图的,所以它不应该位于“Models”文件夹中吗?
对此的任何澄清将不胜感激!
I am learning ASP.NET MVC and looking at the ASP.NET MVC sample application NerdDinner.
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?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,您的想法是正确的。 NerdDinner 的制作只是为了概念演示的目的,并没有真正假装所有的最佳实践。随着你自己的项目的成长,它会变得越来越明显。您将把域实体/服务/存储库放在单独的文件夹中,然后是单独的项目,然后可能是单独的解决方案。您会发现自己将此文件夹重命名为
ViewModels
,以使其对于从事项目的其他人来说更加明显。PaginatedList 可以是 ViewModel 并包含与分页相关的数据。然后可以将其放入
ViewModels
文件夹中。但我相信 NerdDinner 中的内容只是一个简单的视图助手来生成分页标记。此外,助手可能不是那么严格的“View”或“ViewModel”——它们可以包含简单的逻辑,它们在某种程度上处于 View 和 ViewModel 之间的中间:)。另请注意,PaginatedList 更多的是“框架”问题,而不是“特定解决方案”。因此,您不能将其放置在项目特定内容中的“Views”或“Models”文件夹中。所以“Helpers”对于 NerdDinner 来说已经足够了。在真正的解决方案中,您最好使其通用,将其包含到 MVC 之上的“框架”中。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.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.对于第一个问题,
Dinner.cs
文件包含部分Dinner
类以及好友类的一些验证属性。恕我直言,将此文件放入Model
文件夹中是完全明智的,因为它实际上是解决方案模型的一部分。对于第二个问题,
PaginatedList
是一种数据结构,它允许您一次查看数据的某个“页面”(一组固定的元素)。我真的不认为它是一个ViewModel
,它就是一个“助手”。我还想补充的一件事是,如果您有一些 ViewModel 传递到视图中而不是实际的模型类,或者因为您有一组特定的数据元素要传递,我认为这是合理的一个单独的
ViewModel
文件夹。希望这有帮助:)
for the first question, the
Dinner.cs
file contains a partial of theDinner
class along with some validation attributes on a buddy class. It's perfectly sane, IMHO, to put this file into theModel
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 aViewModel
, 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 :)